QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#52925#4808. Great PartyCoder_Z#WA 3ms5716kbC++201.2kb2022-10-04 16:23:122022-10-04 16:23:13

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-04 16:23:13]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5716kb
  • [2022-10-04 16:23:12]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i, a, b) for (int i = (a); i <= (b); i ++)
#define dep(i, a, b) for (int i = (a); i >= (b); i --)

using namespace std;
typedef long long ll;

const int N = 1e5 + 5;
int n, m, a[N], b[N];

int mp[N], t[N];
struct node {
  int l, r, o;
  bool operator < (const node &rhs) const {
    return mp[l] != mp[rhs.l] ? mp[l]  < mp[rhs.l] : r < rhs.r;
  }
} d[N];

ll sum, ans[N];

int main() {
  cin >> n >> m;
  b[0] = 0;
  rep(i, 1, n) {
    int x; cin >> x;
    a[i] = a[i - 1] ^ ((x - 1) | (1 << 20)), b[i] = a[i]; 
  }
  sort(b + 1, b + 1 + n);
  int k = unique(b + 1, b + 1 + n) - (b + 1);
  rep(i, 1, n) a[i] = lower_bound(b + 1, b + 1 + k, a[i]) - b;
  int B = sqrt(n);
  rep(i, 1, n) mp[i] = (i - 1) / B + 1;
  rep(i, 1, m) cin >> d[i].l >> d[i].r, d[i].l --, d[i].o = i;
  sort(d + 1, d + 1 + m);
  int l = 0, r = -1;
  rep(i, 1, m) {
    while ( r < d[i].r ) sum += t[a[++r]] ++;
    while ( l > d[i].l ) sum += t[a[--l]] ++;
    while ( r > d[i].r ) sum -= --t[a[r--]];
    while ( l < d[i].l ) sum -= --t[a[l++]];
    auto calc = [&] (ll x) {
      return x * (x + 1) / 2;
    };
    ans[d[i].o] = calc(d[i].r - d[i].l) - sum;
  }
  rep(i, 1, m) cout << ans[i] << '\n';
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5652kb

input:

4 5
1 2 2 4
1 2
2 3
3 4
1 3
2 4

output:

3
2
3
5
5

result:

ok 5 number(s): "3 2 3 5 5"

Test #2:

score: 0
Accepted
time: 3ms
memory: 5636kb

input:

4 5
5 6 7 8
1 2
2 3
3 4
1 3
2 4

output:

3
3
3
6
6

result:

ok 5 number(s): "3 3 3 6 6"

Test #3:

score: 0
Accepted
time: 2ms
memory: 5716kb

input:

10 10
3 7 3 1 6 6 10 3 3 3
9 10
5 10
3 7
5 6
5 6
9 10
3 10
1 4
6 6
1 4

output:

2
18
14
2
2
2
33
10
1
10

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 5648kb

input:

10 8
91 63 1 34 50 11 10 73 96 67
5 9
2 7
2 5
4 7
1 10
3 3
1 4
5 10

output:

15
21
10
10
55
1
10
21

result:

ok 8 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

10 6
9 539 285 408 615 861 951 413 319 368
4 4
8 10
1 7
3 9
2 3
2 10

output:

1
6
28
28
3
45

result:

ok 6 numbers

Test #6:

score: 0
Accepted
time: 3ms
memory: 5660kb

input:

10 6
1348 7002 4687 6325 8253 5750 2464 5509 6543 8704
3 9
4 8
8 8
8 9
2 9
9 10

output:

28
15
1
3
36
3

result:

ok 6 numbers

Test #7:

score: 0
Accepted
time: 2ms
memory: 5716kb

input:

10 8
59041 28802 92255 14246 65768 79252 70656 81265 98363 85237
1 6
9 10
4 7
6 8
9 10
1 2
1 3
4 5

output:

21
3
10
6
3
3
6
3

result:

ok 8 numbers

Test #8:

score: 0
Accepted
time: 1ms
memory: 5608kb

input:

10 7
28607 249948 373828 584253 989446 308313 199311 253174 283937 133758
2 4
1 2
4 9
7 8
7 8
2 6
1 1

output:

6
3
21
3
3
15
1

result:

ok 7 numbers

Test #9:

score: -100
Wrong Answer
time: 3ms
memory: 5516kb

input:

100 98
6 9 6 10 8 10 3 4 7 5 4 10 2 10 4 5 2 1 7 1 3 1 4 1 1 2 6 9 3 10 2 5 3 2 6 2 1 7 7 6 5 4 2 5 3 2 7 2 6 2 9 7 10 7 4 2 9 3 3 7 9 1 4 9 6 1 5 5 8 3 7 5 8 3 9 5 8 7 8 6 6 3 2 3 8 1 8 1 5 9 1 8 6 3 3 7 10 6 5 5
48 72
14 46
23 28
37 84
1 65
45 72
9 19
9 81
37 53
47 50
25 26
26 88
51 54
53 69
22 94...

output:

316
534
20
1144
2055
394
64
2596
149
10
3
1944
10
148
2598
35
169
6
28
318
605
2964
366
4571
2815
130
1220
52
160
2964
129
3040
793
1491
89
1932
227
64
77
420
332
646
267
1081
902
956
2668
2191
449
149
223
5
3763
1312
102
1221
578
2188
289
681
367
960
1
226
151
720
116
101
3348
905
132
1
88
1140
199...

result:

wrong answer 5th numbers differ - expected: '2054', found: '2055'