UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188351#3318. 缺水(water)ddh1231001895ms11396kbC++111.9kb2023-10-03 08:52:032023-10-03 12:48:07

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
int n,q,a,b,h,l,r;
struct f{
	int l,r,minn,cnt,tag;
}tr[400005],t1,t2;
void pushup(int p){
	tr[p].minn=tr[p<<1|1].minn;
	if(tr[p<<1].minn==tr[p<<1|1].minn)
		tr[p].cnt=tr[p<<1].cnt+tr[p<<1|1].cnt;
	else tr[p].cnt=tr[p<<1|1].cnt;
}
void addtag(int p,int x){
	tr[p].tag+=x,tr[p].minn+=x;
}
void pushdown(int p){
	if(tr[p].tag)
		addtag(p<<1,tr[p].tag),addtag(p<<1|1,tr[p].tag),tr[p].tag=0;
}
void build(int p,int l,int r){
	tr[p]={l,r,0,1};
	if(l==r){
		if(!l)tr[p].minn=1e18;
		return;
	}
	int mid=l+r>>1;
	build(p<<1,l,mid),build(p<<1|1,mid+1,r);
	pushup(p);
}
void update(int p,int l,int r,int val){
	if(tr[p].r<l||tr[p].l>r)
		return;
	if(l<=tr[p].l&&tr[p].r<=r){
		addtag(p,val);
		return;
	}
	pushdown(p);
	update(p<<1,l,r,val),update(p<<1|1,l,r,val),pushup(p);
}
f query(int p,int l,int r){
	if(l<=tr[p].l&&tr[p].r<=r)
		return tr[p];
	pushdown(p);
	int mid=tr[p].l+tr[p].r>>1;
	if(r<=mid)
		return query(p<<1,l,r);
	if(l>mid)
		return query(p<<1|1,l,r);
	f L=query(p<<1,l,r),R=query(p<<1|1,l,r),ans=R;
	if(L.minn==R.minn)ans.cnt+=L.cnt;
	return ans;
}
void out(int p){
	if(tr[p].l==tr[p].r){
		if(tr[p].l)printf("%lld\n",tr[p].minn);
		return;
	}
	pushdown(p),out(p<<1),out(p<<1|1);
}
signed main(){
	n=read(),q=read(),build(1,0,n);
	while(q--){
		a=read(),b=read();
		while(b){
			t1=query(1,0,a);
			t2=query(1,0,a-t1.cnt);
			h=t2.minn-t1.minn,l=a-t1.cnt+1,r=a;
			if(b/t1.cnt>=h)
				update(1,l,r,h),b-=t1.cnt*h;
			else {
				if(b/t1.cnt)update(1,l,r,b/t1.cnt);
				if(b%t1.cnt)update(1,l,l+(b%t1.cnt)-1,1);
				break;
				
			}
		}
	}
	out(1);
	return 0;
}

详细

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

Test #1:

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

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: 1160kb

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: 1160kb

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: 1160kb

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: 1160kb

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: 1160kb

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: 1164kb

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: 1160kb

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: 0ms
memory: 1160kb

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: 89ms
memory: 11396kb

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: 83ms
memory: 11396kb

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: 66ms
memory: 11392kb

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: 64ms
memory: 11392kb

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: 53ms
memory: 11392kb

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: 313ms
memory: 11396kb

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: 332ms
memory: 11392kb

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: 315ms
memory: 11392kb

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: 203ms
memory: 11396kb

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: 321ms
memory: 11392kb

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: 56ms
memory: 11396kb

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