ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188464 | #3318. 缺水(water) | gaojieming | 100 | 6243ms | 6380kb | C++11 | 2.0kb | 2023-10-03 09:46:23 | 2023-10-03 12:49:45 |
answer
#include<bits/stdc++.h>
#define ll long long
#define il inline
#define pn putchar('\n')
#define maxint 2147483647
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
#define maxn 100005
#define int ll
using namespace std;
int n,m;
int a[maxn],smt[maxn<<2],tag[maxn<<2];
il void pt(int pos,int l,int r)
{
smt[pos]=tag[pos>>1]*(r-l+1);
tag[pos]=tag[pos>>1];
}
il void pushtag(int pos,int l,int r)
{
if(tag[pos]==-1)
return;
int mid=l+r>>1;
pt(pos<<1,l,mid);
pt(pos<<1|1,mid+1,r);
tag[pos]=-1;
}
il int fi(int pos,int l,int r,int L,int R)
{
if(L<=l&&r<=R)return smt[pos];
pushtag(pos,l,r);
int mid=l+r>>1;
int ret=0;
if(L<=mid)
ret+=fi(pos<<1,l,mid,L,R);
if(R>mid)
ret+=fi(pos<<1|1,mid+1,r,L,R);
return ret;
}
il void cha(int pos,int l,int r,int L,int R,int ad)
{
if(L<=l&&r<=R)
{
tag[pos]=ad;
smt[pos]=ad*(r-l+1);
return;
}
pushtag(pos,l,r);
int mid=l+r>>1;
if(L<=mid)
cha(pos<<1,l,mid,L,R,ad);
if(R>mid)
cha(pos<<1|1,mid+1,r,L,R,ad);
smt[pos]=smt[pos<<1]+smt[pos<<1|1];
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
scanf("%lld%lld",&n,&m);
memset(tag,-1,sizeof tag);
while(m--)
{
int x,y;
scanf("%lld%lld",&x,&y);
int l=1,r=x,mid,ret=x,anst,ansp;
while(l<=r)
{
mid=l+r>>1;
int t=fi(1,1,n,mid,mid),p=fi(1,1,n,mid,x);
if(t*(x-mid+1)-p<=y)
r=mid-1,ret=mid,anst=t,ansp=p;
else
l=mid+1;
}
int len=x-ret+1;
y-=anst*len-ansp;
if(y%len)
cha(1,1,n,ret,ret+y%len-1,anst+y/len+1),cha(1,1,n,ret+y%len,x,anst+y/len);
else
cha(1,1,n,ret,x,anst+y/len);
}
for(int i=1;i<=n;i++)
printf("%lld\n",fi(1,1,n,i,i));
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 4332kb
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: 4328kb
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: 4328kb
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: 4328kb
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: 4332kb
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: 4332kb
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: 4328kb
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: 2ms
memory: 4328kb
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: 4328kb
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: 688ms
memory: 6376kb
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: 691ms
memory: 6380kb
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: 412ms
memory: 6380kb
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: 509ms
memory: 6380kb
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: 54ms
memory: 4364kb
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: 763ms
memory: 6376kb
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: 775ms
memory: 6376kb
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: 794ms
memory: 6376kb
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: 471ms
memory: 6376kb
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: 776ms
memory: 6376kb
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: 308ms
memory: 6380kb
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