UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188456#3318. 缺水(water)Alan_Zhaoyz100780ms8304kbC++111.0kb2023-10-03 09:41:232023-10-03 12:49:38

answer

#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
const int N=1e5+5;
int n,m;
ll ans[N];
map<int,ll> cnt;
map<int,ll>::iterator split(int p){
	if(!cnt.count(p)){
		ll v=prev(cnt.upper_bound(p))->second;
		cnt[p]=v;
	}
	return prev(cnt.lower_bound(p));
}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cnt[1]=cnt[n+1]=0;
	cin>>n>>m;
	For(test,1,m){
		ll a,b;
		cin>>a>>b;
		auto it=split(a+1);
		for(;it!=cnt.begin();it=prev(cnt.erase(it))){
			ll need=(a-it->first+1)*(prev(it)->second-it->second);
			if(b>=need) b-=need;
			else break;
		}
		ll len=a-it->first+1,pre=it->second;
		it->second+=b/len+1;
		cnt[it->first+b%len]=pre+b/len;
	}
	for(auto it=cnt.begin();next(it)!=cnt.end();++it){
		For(i,it->first,next(it)->first-1){
			ans[i]=it->second;
		}
	}
	For(i,1,n) cout<<ans[i]<<'\n';
	return 0;
}

详细

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

Test #1:

score: 5
Accepted
time: 0ms
memory: 1268kb

input:

32 50
18 1
4 1
23 1
6 1
27 1
27 1
30 1
16 1
13 1
30 1
32 1
7 1
9 1
2 1
16 1
20 1
18 1
32 1
18 1
19 1...

output:

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

result:

ok 32 lines

Test #2:

score: 5
Accepted
time: 0ms
memory: 1272kb

input:

100 100
32 1
8 1
7 1
50 1
77 1
68 1
7 1
2 1
79 1
4 1
27 1
74 1
82 1
27 1
55 1
11 1
35 1
5 1
98 1
79 ...

output:

5
4
4
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
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 100 lines

Test #3:

score: 5
Accepted
time: 0ms
memory: 1268kb

input:

100 100
17 1
64 1
86 1
54 1
11 1
27 1
29 1
40 1
37 1
91 1
12 1
16 1
57 1
28 1
49 1
92 1
19 1
12 1
26...

output:

4
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 100 lines

Test #4:

score: 5
Accepted
time: 0ms
memory: 1272kb

input:

100 100
12 1
77 1
62 1
10 1
50 1
95 1
16 1
29 1
2 1
49 1
12 1
72 1
8 1
97 1
4 1
63 1
97 1
100 1
61 1...

output:

4
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
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 100 lines

Test #5:

score: 5
Accepted
time: 0ms
memory: 1272kb

input:

100 100
64 816364689400
85 250417296792
23 164495457837
45 601283353256
84 579041389006
31 534520274...

output:

976842280582
976842280582
797959751837
797959751837
797959751837
797959751836
742224474014
742224474...

result:

ok 100 lines

Test #6:

score: 5
Accepted
time: 0ms
memory: 1268kb

input:

100 100
28 718964465047
7 575389574219
40 217792530401
59 246661437577
41 922870370119
97 9695024516...

output:

1297067579543
959737595164
959737595164
959737595164
959737595164
959737595164
959737595163
95973759...

result:

ok 100 lines

Test #7:

score: 5
Accepted
time: 0ms
memory: 1272kb

input:

100 100
75 654944644970
94 423275771601
39 716497218928
41 518557560524
28 867505726887
21 600401057...

output:

1453723736623
1453723736623
1067954229729
1067954229728
1067954229728
1067954229728
808931255408
808...

result:

ok 100 lines

Test #8:

score: 5
Accepted
time: 0ms
memory: 1272kb

input:

100 100
100 1000000000
99 2000000000
98 3000000000
97 4000000000
96 5000000000
95 6000000000
94 7000...

output:

423925129284
323925129283
274425129283
241758462616
217508462616
198308462616
182475129282
169046557...

result:

ok 100 lines

Test #9:

score: 5
Accepted
time: 1ms
memory: 1268kb

input:

100 100
31 1000000000000
42 1000000000000
58 1000000000000
56 1000000000000
48 1000000000000
18 1000...

output:

1966527736113
1966527736113
1966527736113
1299861069446
1299861069446
1299861069446
1202229004193
12...

result:

ok 100 lines

Test #10:

score: 5
Accepted
time: 67ms
memory: 2160kb

input:

100000 100000
96548 1
90362 1
86350 1
23476 1
59612 1
80822 1
87627 1
88257 1
98177 1
39138 1
27392 ...

output:

7
7
7
7
7
7
7
7
7
7
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
...

result:

ok 100000 lines

Test #11:

score: 5
Accepted
time: 66ms
memory: 2156kb

input:

100000 100000
91573 1
47872 1
49859 1
77860 1
45771 1
37881 1
8131 1
143 1
29369 1
56879 1
23484 1
9...

output:

7
7
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
...

result:

ok 100000 lines

Test #12:

score: 5
Accepted
time: 28ms
memory: 2052kb

input:

100000 100000
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
...

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
...

result:

ok 100000 lines

Test #13:

score: 5
Accepted
time: 134ms
memory: 8300kb

input:

100000 100000
100000 1
99999 1
99998 1
99997 1
99996 1
99995 1
99994 1
99993 1
99992 1
99991 1
99990...

output:

17
16
15
14
14
14
13
13
13
13
13
13
12
12
12
12
12
12
12
12
12
12
12
12
11
11
11
11
11
11
11
11
11
1...

result:

ok 100000 lines

Test #14:

score: 5
Accepted
time: 23ms
memory: 1276kb

input:

100000 100000
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 ...

output:

50000
50000
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 lines

Test #15:

score: 5
Accepted
time: 77ms
memory: 2068kb

input:

100000 100000
17511 848005075244
9363 239981338428
19259 819886704704
29901 177853370945
89418 30446...

output:

970339585120
970339585120
970339585120
783324034191
783324034191
783324034191
783324034191
783324034...

result:

ok 100000 lines

Test #16:

score: 5
Accepted
time: 77ms
memory: 2072kb

input:

100000 100000
71267 368627219055
67335 826972000428
52026 497146819579
63121 224922913539
56108 5410...

output:

1074749497547
1074749497546
1074749497546
1074749497546
1074749497546
1074749497546
972279345467
972...

result:

ok 100000 lines

Test #17:

score: 5
Accepted
time: 71ms
memory: 2072kb

input:

100000 100000
72499 244745670180
96915 233414658355
54588 629661705335
74019 73173264118
29651 31999...

output:

1766056907925
1187810699402
1187810699402
1187810699402
1001275072713
1001275072713
1001275072712
10...

result:

ok 100000 lines

Test #18:

score: 5
Accepted
time: 125ms
memory: 8304kb

input:

100000 100000
100000 10000000
99999 20000000
99998 30000000
99997 40000000
99996 50000000
99995 6000...

output:

11090267031330
10090267031330
9590272031329
9256945364663
9006952864663
8806960864663
8640302531329
...

result:

ok 100000 lines

Test #19:

score: 5
Accepted
time: 82ms
memory: 2072kb

input:

100000 100000
52459 1000000000000
23550 1000000000000
87294 1000000000000
82741 1000000000000
96320 ...

output:

1895152601536
1895152601536
1895152601535
1895152601535
1895152601535
1895152601535
1861225435872
18...

result:

ok 100000 lines

Test #20:

score: 5
Accepted
time: 29ms
memory: 2052kb

input:

100000 100000
100000 1000000000000
100000 1000000000000
100000 1000000000000
100000 1000000000000
10...

output:

1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
1000000000000
10...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed