QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#846286#9991. 背向而行CrysflyAC ✓296ms24624kbC++142.2kb2025-01-07 02:43:142025-01-07 02:43:14

Judging History

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

  • [2025-01-07 02:43:14]
  • 评测
  • 测评结果:AC
  • 用时:296ms
  • 内存:24624kb
  • [2025-01-07 02:43:14]
  • 提交

answer

// what is matter? never mind. 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define ull unsigned long long
#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f?-x:x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 2000005
#define inf 0x3f3f3f3f

int m;
struct node{
	int l,r,x;
	int sum,cnt;
};
node st[maxn];
int tp;
int S(int n){
	return n*(n-1)/2;
}
node gen(int sum,int cnt){
	node t;
	t.sum=sum,t.cnt=cnt;
	
	sum-=S(cnt);
	t.l=sum/cnt;
	sum-=t.l*cnt;
//	cout<<"now_sum "<<sum<<" "<<t.l<<endl;
	if(sum<0) t.l--,sum+=cnt;
	if(sum==0) t.x=-1,t.r=t.l+cnt-1;
	else t.r=t.l+cnt,t.x=t.r-sum;
	
	return t;
}

int pre[maxn];

signed main()
{
	m=read();
	
	node t=gen(17,5);
//	cout<<"?? "<<t.l<<" "<<t.r<<" "<<t.x<<endl;
	
	For(i,1,m){
		int x=read(),c=read();
		node t=gen(x*c,c);
		while(tp && st[tp].r>=t.l){
			t=gen(st[tp].sum+t.sum,st[tp].cnt+t.cnt);
			--tp;
		}
		st[++tp]=t;
	}
	For(i,1,tp) pre[i]=pre[i-1]+(st[i].r-st[i].l+1-(st[i].x!=-1));
	
//	For(i,1,tp) cout<<"range "<<st[i].l<<" "<<st[i].r<<" "<<st[i].x<<endl;
	
	int q=read();
	For(i,1,q){
		int k=read();
		int p=lower_bound(pre+1,pre+tp+1,k)-pre;
		k-=pre[p-1];
		int res=0;
		
		res=st[p].l+k-1;
		if(st[p].x!=-1 && res>=st[p].x)++res;
		printf("%lld\n",res);
	}
    return 0;
}
/*
9 8


9 105
801 919 210 101 417 713 304 613 921
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 2 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1


1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 2 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1

1 1 1 1
1 1 2 1

1 1 1 0 0 1 1 0

0 1 1 1 1 1 1 4 4 5 8 9 9 
*/

详细

Test #1:

score: 100
Accepted
time: 296ms
memory: 24624kb

input:

1950000
1 794
2 7
1369 16
1423 107
1618 2
2068 7
2565 1037
2571 35
3426 108
4118 22
6509 4
8123 45
11757 11
11798 14
11812 48
11970 6
11990 670
12040 1
12072 120
12900 223
12901 58
12957 64
14526 1
14530 1
14917 95
16490 433
16676 39
16732 118
16861 1604
16866 327
16933 1
16992 78
17776 1
18052 90
1...

output:

-171
7
217
2190
2317
2383
2601
11865
12847
12883
14902
16491
16882
18034
22684
23134
23302
25025
25040
25289
25470
25495
25583
32728
32921
33131
33400
33808
33931
34043
34096
34165
34262
36052
36218
36303
36400
40263
40269
42899
42957
43406
43455
43531
43585
43731
43774
43805
44091
44594
44949
45458...

result:

ok 2000000 lines

Test #2:

score: 0
Accepted
time: 261ms
memory: 3892kb

input:

1950000
1 195
147 172
367 2
385 2
386 5
403 3
507 1176
559 237
567 1419
1121 307
1285 3177
1287 818
1511 368
1748 2055
5672 738
5674 1
5681 571
5730 3433
6618 3015
6685 303
6979 102
7100 10
7114 506
7124 123
7129 618
7132 2
7183 6
11116 19
11221 1524
14141 54
14153 38
14274 16
14283 37
14639 1
14643...

output:

-235711
-235683
-235503
-234922
-234316
-234213
-233625
-232430
-232381
-232316
-232216
-232057
-231395
-230462
-230445
-229260
-229223
-228108
-227880
-227659
-225372
-224977
-224738
-224674
-224272
-223572
-223201
-223011
-222696
-221906
-221329
-220372
-219890
-219711
-219542
-219363
-219235
-219...

result:

ok 2000000 lines

Test #3:

score: 0
Accepted
time: 260ms
memory: 3828kb

input:

1950000
1 5
51 1
1760 2587
1766 175
1885 54
1886 912
2490 26
2491 380
2524 22
2604 68
2677 6
2678 19
2772 3830
2781 24
2970 59
3009 496
3015 207
3062 15
3488 104
5263 2110
5745 176
6641 230
6642 1
6684 991
7139 664
8688 2
9137 57
9138 458
9140 314
9176 962
9296 3292
9309 697
9336 448
10773 229
10801...

output:

-34109
-32734
-31986
-31809
-30628
-29900
-29096
-27297
-27140
-27116
-26093
-24912
-24529
-23998
-23866
-23675
-23318
-22950
-22722
-21612
-19988
-19394
-18975
-17938
-17921
-17557
-17063
-16999
-16672
-16248
-15205
-15110
-14993
-14741
-14417
-14069
-14004
-13574
-12662
-11018
-10814
-10283
-9366
...

result:

ok 2000000 lines

Test #4:

score: 0
Accepted
time: 242ms
memory: 3872kb

input:

1950000
1 14
18 89
3545 973
4456 4
4717 5
4722 92
4861 4
4863 248
4869 218
6024 252
6031 2
9823 7
9829 6
9830 36
9832 1136
10269 164
10335 3
10455 4034
10461 72
10465 14
10509 49
10515 9
10518 1489
11331 2
12751 1
12758 943
12759 4038
12969 21
12970 2
12973 3
12975 491
13181 58
13184 4
13190 897
132...

output:

-1739184
-1739173
-1738832
-1738713
-1737100
-1736137
-1736021
-1734772
-1734472
-1733474
-1733107
-1732851
-1732705
-1732410
-1729430
-1729355
-1729243
-1728437
-1728379
-1727789
-1727252
-1726237
-1725751
-1725608
-1725478
-1725246
-1725006
-1724785
-1724167
-1724015
-1723935
-1723734
-1722932
-17...

result:

ok 2000000 lines

Test #5:

score: 0
Accepted
time: 154ms
memory: 3876kb

input:

80000
1 3652
90821 22
93475 53633
93981 1
93989 214
94102 5882
126457 2063
127496 238
127499 28
134269 51733
137088 4
137097 11
137125 32
137212 90
137219 61
137223 1434
233679 4633
333645 887
333680 394
333691 55
333791 2836
333980 9405
338143 58463
338344 8
338349 1023
338425 249
338486 122
338488...

output:

-9431525
-9431177
-9430768
-9428371
-9427400
-9427028
-9427019
-9426730
-9426713
-9426560
-9426202
-9426045
-9426011
-9425163
-9423909
-9423899
-9423465
-9423064
-9423052
-9422682
-9421895
-9420275
-9419700
-9419601
-9419294
-9418917
-9418736
-9418620
-9418584
-9418489
-9418279
-9417846
-9417769
-94...

result:

ok 2000000 lines

Test #6:

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

input:

80000
1 113
3 159
5899 2
6079 31
6081 704
6103 7749
6116 17241
6720 13
6742 41818
6747 1
6925 6663
12151 1
12378 72
13092 73
13094 118903
13113 100161
13125 117530
13148 3
13223 11
13983 10419
15138 113
93687 4
157627 6687
159191 122597
169994 127024
170778 7
278676 58704
278892 11748
278899 13
2871...

output:

-948313
-945010
-943896
-943876
-943680
-942582
-942209
-941554
-941518
-941471
-940054
-939348
-939048
-938973
-938423
-938264
-937784
-937385
-937350
-937067
-936672
-936669
-935764
-935603
-935118
-934439
-934286
-933821
-933257
-933128
-931340
-931262
-929676
-929485
-929450
-928557
-928471
-928...

result:

ok 2000000 lines

Test #7:

score: 0
Accepted
time: 173ms
memory: 4420kb

input:

80000
1 2
43033 83
43142 65489
51236 25096
51239 99
51241 2033
52734 6
72833 10
73445 7
73466 14
80038 1609
80541 12307
87403 3
128905 4043
128908 3
129075 265
175800 54
175819 181
176368 103
176370 5
176423 47481
202006 265
202103 23420
218091 1
218092 44031
348974 82
379787 874
380141 6426
386824 ...

output:

-3223
-3168
-3028
-2937
-2856
-2825
-2126
-1562
-1539
-1447
-1220
-1197
-707
811
899
1419
1653
1964
2200
2428
2494
2506
2874
2945
3057
3132
3161
3264
3627
3776
3924
4421
4536
4733
4914
5027
5420
5495
6126
6163
6243
6485
6518
6719
6738
6777
7014
7161
7254
7282
7626
7644
7701
7736
7799
7985
8290
8360
...

result:

ok 2000000 lines

Test #8:

score: 0
Accepted
time: 254ms
memory: 3972kb

input:

2000000
1 25
223 2
226 34
353 1
386 115
615 3
676 13
911 2
920 6
1043 62
1073 257
1312 14
1567 108
1570 433
1571 1
1613 269
1701 10
1702 29
1936 268
1937 62
1938 301
2415 1
2444 8
2466 15
2467 6
2821 44
2833 6
2848 205
3011 96
3045 1
3088 83
3156 10
3447 190
3455 211
3457 48
3470 16
3480 220
3914 31...

output:

-37821
-37748
-37735
-37599
-37593
-37469
-37433
-37423
-37373
-37324
-37199
-37108
-37095
-36974
-36885
-36785
-36764
-36731
-36552
-36519
-36378
-36375
-36151
-36118
-35701
-35625
-35542
-35358
-35054
-34974
-34693
-34621
-34497
-34482
-34296
-34201
-34189
-34124
-34112
-33788
-33706
-33567
-33444...

result:

ok 2000000 lines

Test #9:

score: 0
Accepted
time: 277ms
memory: 8372kb

input:

2000000
1 29
2 936
17 25
31 1281
32 3
188 282
208 20
210 2
907 2
909 7
2023 437
2159 3
2162 1
2259 2
2288 13
2308 5
2690 1368
4309 4
5045 61
6131 2
6281 417
6283 1
7106 341
7107 20
7112 784
7233 740
7500 445
7501 364
9189 1635
9915 34
11021 36
11397 845
11601 185
11825 56
12363 30
13862 2
15143 3
15...

output:

-1222
-1132
-980
-954
-932
-721
-684
-670
-425
-240
-198
-112
64
308
1124
1770
1896
1909
2171
2270
2854
2886
3035
3149
6480
6496
6573
7576
7601
7792
7973
8001
8472
8817
9087
9099
9525
9569
9745
9825
9865
10052
10124
10896
10971
11122
11295
11322
11985
13350
13442
13839
13957
14097
14859
15520
15751
...

result:

ok 2000000 lines