ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188331 | #3318. 缺水(water) | Harry27182 | 100 | 6587ms | 7400kb | C++11 | 1.6kb | 2023-10-03 08:43:02 | 2023-10-03 12:47:48 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct tree{int len,val,tag;}tr[400005];
int n,m,a,b;
void build(int k,int l,int r)
{
tr[k]={r-l+1,0,0};
if(l==r)return;
int mid=(l+r)>>1;
build(k<<1,l,mid);build(k<<1|1,mid+1,r);
}
void pushup(int k){tr[k].val=tr[k<<1].val+tr[k<<1|1].val;}
void update(int k,int v){tr[k].val=tr[k].len*v;tr[k].tag=v;}
void pushdown(int k)
{
if(!tr[k].tag)return;
update(k<<1,tr[k].tag);update(k<<1|1,tr[k].tag);
tr[k].tag=0;
}
void change(int k,int l,int r,int x,int y,int v)//区间赋值
{
if(x>y)return;
if(x<=l&&r<=y){update(k,v);return;}
int mid=(l+r)>>1;pushdown(k);
if(x<=mid)change(k<<1,l,mid,x,y,v);
if(y>mid)change(k<<1|1,mid+1,r,x,y,v);
pushup(k);
}
int query(int k,int l,int r,int x,int y)//区间查询
{
if(x>y)return 0;
if(x<=l&&r<=y)return tr[k].val;
int mid=(l+r)>>1,res=0;pushdown(k);
if(x<=mid)res+=query(k<<1,l,mid,x,y);
if(y>mid)res+=query(k<<1|1,mid+1,r,x,y);
return res;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;build(1,1,n);
while(m--)
{
cin>>a>>b;
int l=1,r=a,pos=-1;//能把 pos+1~a 全部覆盖为 val[pos]
while(l<=r)
{
int mid=(l+r)>>1;
int val=query(1,1,n,mid,mid);
int need=val*(a-mid)-query(1,1,n,mid+1,a);
if(need<=b)pos=mid,r=mid-1;
else l=mid+1;
}
int val=query(1,1,n,pos,pos);
int need=val*(a-pos)-query(1,1,n,pos+1,a);
b-=need;
//剩下的要覆盖在 pos~a 上
int len=a-pos+1;
int x=b/len,y=b%len;
change(1,1,n,pos,pos+y-1,val+x+1);
change(1,1,n,pos+y,a,val+x);
}
for(int i=1;i<=n;i++)cout<<query(1,1,n,i,i)<<'\n';
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1244kb
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: 1252kb
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: 1ms
memory: 1252kb
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: 1248kb
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: 1252kb
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: 1248kb
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: 1252kb
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: 1ms
memory: 1248kb
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: 1248kb
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: 694ms
memory: 7396kb
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: 699ms
memory: 7400kb
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: 534ms
memory: 7400kb
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: 571ms
memory: 7400kb
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: 92ms
memory: 7396kb
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: 776ms
memory: 7396kb
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: 779ms
memory: 7400kb
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: 748ms
memory: 7396kb
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: 613ms
memory: 7396kb
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: 753ms
memory: 7396kb
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: 326ms
memory: 7400kb
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