QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#672960#8714. 组合数ucup-team4479AC ✓211ms24720kbC++232.5kb2024-10-24 20:01:562024-10-24 20:01:57

Judging History

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

  • [2024-10-24 20:01:57]
  • 评测
  • 测评结果:AC
  • 用时:211ms
  • 内存:24720kb
  • [2024-10-24 20:01:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=300005;
struct Node
{
    int op,val,x,y,id;
}a[N];
struct BIT
{
    int c[N];
    int lowbit(int x)
    {
        return x&-x;
    }
    void add(int x,int y)
    {
        for(int i=x;i<N;i+=lowbit(i))
            c[i]+=y;
        return;
    }
    int query(int x)
    {
        x=min(x,N-1);
        int res=0;
        for(int i=x;i>0;i-=lowbit(i))
            res+=c[i];
        return res;
    }
}T;
int ans[N];
void cdq(int l,int r)
{
    if(l==r) return;
    int mid=(l+r)>>1;
    cdq(l,mid);
    cdq(mid+1,r);
    vector<Node>b;
    for(int i=l;i<=mid;i++)
        if(a[i].op) b.emplace_back(a[i]);
    for(int i=mid+1;i<=r;i++)
        if(!a[i].op) b.emplace_back(a[i]);
    sort(b.begin(),b.end(),[&](const Node &a,const Node &b){return a.x<b.x||(a.x==b.x&&abs(a.op)>abs(b.op));});
    for(int i=0;i<(int)b.size();i++)
        if(b[i].op) T.add(b[i].y, b[i].op);
        else
        {
            if(b[i].id>0) ans[b[i].id]+=T.query(b[i].y);
            else ans[-b[i].id]-=T.query(b[i].y);
        }
    for(int i=0;i<(int)b.size();i++)
        if(b[i].op) T.add(b[i].y,-b[i].op);
    return;
}
int tot;
map<int,vector<pair<int,int>>>mp;
void init(int n)
{
    for(int i=4;(long long)i*(i-1)/2<=n;i++)
    {
        long long val=i;
        for(int j=2;j<=i/2;j++)
        {
            val*=(i-j+1);
            val/=j;
            if(val>n) break;
            mp[val].emplace_back(i,j);
        }
    }
    for(auto &[val,pos]:mp)
    {
        int m=pos.size();
        for(int s=1;s<(1<<m);s++)
        {
            int mxx=0,mxy=0,f=-1;
            for(int i=0;i<m;i++)
                if((s>>i)&1)
                {
                    mxx=max(mxx,pos[i].first);
                    mxy=max(mxy,pos[i].second);
                    f=-f;
                }
            a[++tot]={f,val,mxx,mxy,0};
        }
    }
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int q;
    cin>>q;
    init(1e9);
    for(int t=1;t<=q;t++)
    {
        int l,r,n,m;
        cin>>l>>r>>n>>m;
        if(n+1<=r)
        {
            a[++tot]={0,max(l,n+1)-1,n,m,-t};
            a[++tot]={0,r,n,m,t};
        }
        ans[t]=max(0,min(n,r)-l+1);
    }
    sort(a+1,a+tot+1,[&](const Node &a,const Node &b){return a.val<b.val||(a.val==b.val&&abs(a.op)>abs(b.op));});
    cdq(1,tot);
    for(int i=1;i<=q;i++)
        cout<<ans[i]<<endl;
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 34ms
memory: 13572kb

input:

2
1 6 4 2
30 60 9 3

output:

5
3

result:

ok 2 number(s): "5 3"

Test #2:

score: 0
Accepted
time: 156ms
memory: 19508kb

input:

100000
707 991 95 6
343 919 51 1
681 860 78 9
103 406 37 14
318 397 115 16
495 560 27 9
100 694 189 17
11 175 11 12
342 659 65 7
194 404 157 14
194 436 191 16
127 908 22 1
333 615 149 11
15 620 83 12
831 940 89 12
298 902 164 15
330 350 56 5
432 983 135 5
23 588 115 15
154 635 130 17
81 549 12 3
208...

output:

12
0
7
22
5
2
118
15
15
13
15
0
14
103
3
28
1
24
123
28
4
12
18
1
10
32
11
18
11
4
1
4
0
22
9
7
0
16
20
29
0
10
100
9
145
6
1
0
12
7
0
130
11
55
6
12
14
14
3
17
3
18
9
15
0
6
14
6
1
12
11
7
60
17
12
19
10
209
12
0
82
10
28
20
3
9
9
127
0
17
7
2
35
15
0
35
5
29
3
20
30
22
14
50
10
7
10
9
12
5
7
5
17
...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 27ms
memory: 11536kb

input:

600
1 120 10 1
120 120 10 1
1 120 10 2
120 120 10 2
1 120 10 3
120 120 10 3
1 120 10 4
120 120 10 4
1 120 10 5
120 120 10 5
1 120 10 6
120 120 10 6
1 120 10 7
120 120 10 7
1 120 10 8
120 120 10 8
1 120 10 9
120 120 10 9
1 120 10 10
120 120 10 10
1 120 10 11
120 120 10 11
1 120 10 12
120 120 10 12
1 ...

output:

10
0
15
0
20
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
21
1
16
0
26
1
30
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
31
1
10
0
15
0
20
0
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
23
1
...

result:

ok 600 numbers

Test #4:

score: 0
Accepted
time: 138ms
memory: 16752kb

input:

100000
60751622 681825789 921564801 18
480281506 788265066 947862226 14
244780384 810641780 511409456 1
442412768 893244158 629324426 19
904988862 967819107 627312423 12
753180456 833077356 230270519 5
31899300 240388180 190425411 10
762418128 865768903 104394602 8
41068547 846933502 528600832 9
213...

output:

621074168
307983561
266629073
186918703
1501
2075
158528637
2652
487541251
664265500
52254549
289471650
280435975
7676
338
443539227
363838721
288817318
14619262
405767161
127704706
522255264
297361699
562261689
103771929
4730
1294
90900464
43764273
348707389
244668585
216719972
22963
389780887
1334...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 211ms
memory: 24272kb

input:

100000
22177563 782229760 3303 20
32416373 327453277 19513 20
296785893 740668968 42732 7
298148008 813059131 18292 5
765921502 914054335 28819 20
433937432 643493272 24550 12
218086833 954961114 47291 7
531126184 632211488 28333 7
330647392 547096297 16562 6
322975021 905706405 45323 5
597623308 75...

output:

1600
12400
14678
593
134
257
23708
113
292
17774
162
25892
0
11423
3364
4250
1579
201
210
20570
547
22
23141
0
1492
0
27188
3184
331
11586
0
16718
3683
1038
197
4413
35
17162
1324
7203
893
9814
150
23
6668
5511
3134
18646
1400
3217
171
128
11710
481
9178
2380
922
2721
12183
15974
47
547
8229
897
194...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 85ms
memory: 13884kb

input:

100000
1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 164ms
memory: 19720kb

input:

100000
1 1000000000 12821 16
1 1000000000 38505 18
1 1000000000 47303 16
1 1000000000 18618 19
1 1000000000 45455 19
1 1000000000 41770 11
1 1000000000 16656 6
1 1000000000 2475 16
1 1000000000 7897 8
1 1000000000 14109 16
1 1000000000 24573 15
1 1000000000 33474 2
1 1000000000 2859 19
1 1000000000 ...

output:

28039
79254
94229
39589
92389
85738
35495
7471
18142
30605
51461
66689
8232
47449
62328
8888
1003
24312
2081
86576
58845
90729
71586
63925
36120
42170
31377
6446
46511
52749
90016
91705
40110
82431
37377
18598
78763
44143
84876
68249
56454
58894
85277
24262
24443
12765
44636
68129
44197
73239
58104
...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 168ms
memory: 19644kb

input:

100000
1 655084100 41613 17
1 91062490 16475 1
1 184271405 26482 14
1 635523680 8267 6
1 596481063 7536 14
1 851882829 9728 2
1 540346160 14396 4
1 156754752 24685 9
1 308994436 19163 20
1 843854100 21159 4
1 678300832 16450 15
1 845209831 33716 6
1 97060161 5206 5
1 71902742 23912 1
1 305651557 692...

output:

79728
16475
46939
18469
17139
19317
30371
43546
39895
44129
34979
69391
11402
23912
15466
42640
17607
9929
91158
45766
59607
36528
30545
45641
47962
74011
79497
54177
73366
29518
70135
35772
67024
13901
38842
63280
84571
20957
12483
68396
51618
41430
51947
52126
40259
11793
23489
31335
58780
83204
1...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 195ms
memory: 24720kb

input:

100000
674490198 1000000000 44627 3
91627196 1000000000 45309 9
717331444 1000000000 11850 10
717538026 1000000000 19838 6
883658590 1000000000 37613 15
748014435 1000000000 40560 20
366141922 1000000000 15959 14
236817685 1000000000 642 6
285515020 1000000000 34103 1
463525931 1000000000 47104 18
3...

output:

8123
32495
246
239
96
2102
682
181
0
14816
4314
79
751
27289
638
12032
27839
155
513
12353
232
11041
692
208
6367
21294
6358
118
770
0
136
147
1106
209
30901
18789
0
27603
52
6284
23204
35856
39
9221
339
29541
9731
1070
1717
106
6230
68
62
45
0
0
296
78
18850
29
58
25751
1612
33130
10765
526
3331
35...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 180ms
memory: 19300kb

input:

100000
91542233 93343098 3060 11
3248602 42629911 4780 6
40232149 70302399 399 11
10927626 87837643 3800 8
45185341 45780205 1995 2
14051503 33946455 3499 7
34438487 71849076 4963 12
38233118 58335575 1459 7
904342 64128070 359 6
84508276 89182769 2046 6
47412806 59738662 3003 1
74309141 80206862 13...

output:

9
2736
52
564
0
208
234
126
398
18
0
0
170
175
0
612
148
0
33
18
111
66
211
200
1902
158
1738
299
339
454
297
78
21
652
253
134
158
0
142
63
10
227
10
130
146
270
18
51
193
280
223
142
159
323
37
526
0
566
327
16
310
326
141
34
193
248
91
0
38
17
105
677
96
294
13
522
381
148
94
13
38
14
1192
1335
5...

result:

ok 100000 numbers

Test #11:

score: 0
Accepted
time: 167ms
memory: 18832kb

input:

100000
36367 78944 635 6
58300 83225 865 6
1856 85254 282 4
13606 32781 498 10
18202 52762 982 5
37745 66491 86 3
77566 88452 254 3
47860 91961 294 5
89316 95100 959 4
25424 87621 670 7
45351 79643 250 10
36389 58727 14 3
5457 10169 479 5
43687 88381 376 10
38120 79148 689 2
27032 36330 956 6
37929 ...

output:

156
83
300
119
167
13
3
26
15
244
27
0
50
112
122
48
31
62
223
0
3
174
23
257
203
54
107
7
208
307
114
450
54
261
93
0
0
211
35
0
60
0
17
34
35
83
270
143
195
334
2
204
8
100
71
219
2
133
43
222
0
0
121
902
150
27
34
67
0
223
154
9
40
52
153
145
73
151
1
0
132
109
246
337
168
0
219
5
0
179
117
0
1
1...

result:

ok 100000 numbers

Test #12:

score: 0
Accepted
time: 171ms
memory: 18836kb

input:

100000
1416 1839 544 10
3400 11612 730 5
14439 23149 344 3
19662 23939 749 3
15668 23278 429 4
72 2003 80 7
11995 23371 984 7
2958 15422 446 8
4786 8387 742 3
12342 18670 210 9
788 5765 134 4
4920 6306 757 1
14910 16825 719 9
5398 10523 509 9
15941 18910 522 8
4279 19853 609 10
19558 22637 264 9
753...

output:

11
92
52
24
47
86
80
136
37
49
89
0
14
55
20
145
20
4
9
10
146
71
129
0
196
52
0
75
102
30
167
112
3
12
2
18
134
37
63
139
76
33
52
8
121
20
120
27
0
6
19
74
162
61
150
103
67
11
24
0
5
138
1
65
84
122
13
12
544
700
0
14
0
116
59
52
2
136
74
0
82
1
0
205
2
138
0
69
58
33
0
13
0
152
0
0
0
790
0
66
14...

result:

ok 100000 numbers

Test #13:

score: 0
Accepted
time: 159ms
memory: 20404kb

input:

100000
8940 235538 820 9
12265 188044 92 9
15945 27041 132 14
326 217182 973 4
5357 206583 696 7
9216 146992 549 8
8322 128869 952 10
13286 24675 79 7
21137 185212 133 1
15354 143492 59 1
23941 153652 451 18
580 85534 64 8
2185 219810 404 15
23204 24141 994 2
6743 126223 866 11
13987 49281 378 1
305...

output:

692
108
17
1388
675
513
485
17
0
0
317
141
501
5
495
0
641
728
190
276
563
0
324
2
248
97
442
152
186
153
78
646
358
561
178
84
208
104
8
483
291
765
159
130
123
0
524
436
176
356
341
368
57
125
129
0
486
8
420
49
31
457
217
583
73
328
0
231
374
440
21
106
164
48
368
460
547
289
0
30
389
94
37
170
2...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed