UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215509#2077. patrickCynops1001609ms5260kbC++1.2kb2025-02-14 08:15:542025-02-14 08:15:55

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define rep(i,l,r) for (int i = l; i <= r; i ++)
#define rrp(i,l,r) for (int i = l; i >= r; i --)
const int N = 1e6 + 5;
int n, m, lst, a[N];
struct bit {
  int c[N];
  void add (int x, int v) {
    for (; x <= N / 2; x += x & (-x)) c[x] += v;
  }
  void upd (int i, int v) { 
    if (a[i-1] < a[i]) add(a[i-1], v), add(a[i], -v);
  }
  int sum(int x) {
    int ans = 0;
    for (; x; x -= x & (-x)) ans += c[x];
    return ans;
  }
} t;
void fakemain() {
  cin >> n >> m, a[0] = 1;
  rep (i, 1, n) cin >> a[i], ++ a[i], t.upd(i, 1);
  rep (i, 1, m) {
    char op; int x, y;
    cin >> op >> x, x ^= lst;
    if (op == 'Q') cout << (lst = t.sum(x)) << '\n';
    else {
      cin >> y, y ^= lst, ++ y;
      t.upd(x, -1), t.upd(x + 1, -1);
      a[x] = y, t.upd(x, 1), t.upd(x + 1, 1);
    }
  }
}
signed main() {
#ifdef heige
  freopen("patrick.in", "r", stdin);
  freopen("patrick.out", "w", stdout);
#endif
  cin.tie(0)->ios::sync_with_stdio(0);
  int T = 1;
  while (T --) fakemain();
  cerr << 1. * clock() / 1000000 << "s\n";
  return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 3ms
memory: 1780kb

input:

5000 5000
11618 17338 26007 30645 41495 8577 28220 3557 61048 54271 12735 30554 19117 24912 71916 49...

output:

1217
1237
821
365
1135
1211
1237
1116
1016
1243
1179
1212
347
904
462
21
1084
1100
1146
56
1003
1013...

result:

ok 2508 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 1784kb

input:

5000 5000
42781 68835 20862 71700 5933 7140 30423 64165 68706 48054 21418 34952 36459 97560 1772 607...

output:

1170
902
271
460
548
1219
748
760
1025
695
801
1208
51
1207
191
1035
1054
93
202
79
530
532
861
438
...

result:

ok 2509 lines

Test #3:

score: 10
Accepted
time: 3ms
memory: 1780kb

input:

5000 5000
60808 84070 31811 47365 75619 62284 2581 79641 72061 80156 33934 16942 25000 66064 57202 5...

output:

1183
994
31
158
224
115
1049
1202
1175
525
1002
51
663
1210
446
1191
1150
889
1079
1177
416
1209
849...

result:

ok 2547 lines

Test #4:

score: 10
Accepted
time: 267ms
memory: 5256kb

input:

500000 500000
434137 376219 73435 423036 76491 303408 102448 338828 69875 129478 243716 421147 31592...

output:

98072
121513
123051
2812
44889
104264
124972
123583
113689
56410
113385
108806
88021
112511
124641
2...

result:

ok 500000 lines

Test #5:

score: 10
Accepted
time: 279ms
memory: 5256kb

input:

500000 500000
327558 296576 192637 469428 399577 209259 271256 286868 410902 236457 141261 191443 26...

output:

5762
77131
81889
17491
32828
112750
124941
72798
124170
108653
77847
107448
31853
18930
77402
34449
...

result:

ok 500000 lines

Test #6:

score: 10
Accepted
time: 314ms
memory: 5256kb

input:

500000 500000
331273 70363 482686 148091 231329 25731 312057 350815 71400 129967 88289 442354 423136...

output:

53946
124566
124905
69402
124146
124976
92287
110542
120860
122557
120849
19871
104123
123390
21447
...

result:

ok 500000 lines

Test #7:

score: 10
Accepted
time: 59ms
memory: 3696kb

input:

100000 100000
452172 464888 314423 267249 442680 360343 19632 341976 115526 300385 18455 172824 3591...

output:

16186
17322
23349
14573
5608
21906
5942
3379
21224
20782
21848
20273
22206
24380
1958
22313
20577
22...

result:

ok 50202 lines

Test #8:

score: 10
Accepted
time: 48ms
memory: 3696kb

input:

100000 100000
92691 110061 365569 179484 447960 127240 193963 70505 338364 452003 66473 63721 407006...

output:

19227
17089
18937
8421
24255
23511
18585
19580
23842
24908
20467
15337
17348
10050
9947
24881
22780
...

result:

ok 50035 lines

Test #9:

score: 10
Accepted
time: 333ms
memory: 5260kb

input:

500000 500000
230546 43633 320357 293808 381361 136978 286284 379946 367590 183794 362424 147508 246...

output:

79022
87923
6292
32428
37116
125126
82270
118323
43719
113469
82845
14057
18792
118967
93087
38413
2...

result:

ok 249940 lines

Test #10:

score: 10
Accepted
time: 303ms
memory: 5256kb

input:

500000 500000
358202 474862 444709 448091 30620 234558 269129 267684 405954 191727 347456 97683 2255...

output:

93019
84369
32373
125041
112262
30223
33014
60264
77768
23
91412
32835
116289
97805
59930
105620
656...

result:

ok 249954 lines