QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184065 | #2029. Minimum Cost Paths | paul2008# | 0 | 0ms | 0kb | C++14 | 2.5kb | 2023-09-20 11:28:41 | 2024-07-04 02:05:15 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
struct node
{
int add,cov; //懒惰标记
int lc,rc; //左右儿子
long long sum,Max;
};
vector <pair<int,int> > que[N];
node res[N*35];
int c[N],root,cnt;
long long ans[N];
void pushup(int rt)
{
res[rt].sum=res[res[rt].lc].sum+res[res[rt].rc].sum;
res[rt].Max=max(res[res[rt].lc].Max,res[res[rt].rc].Max);
}
void Add(int rt,int L,int R,int cov,int add)
{
if(cov)
{
res[rt].cov=cov;
res[rt].add=add;
res[rt].Max=cov+(long long)add*(2*R-1);
res[rt].sum=(long long)cov*(R-L+1)+(long long)add*(L+R-1)*(R-L+1);
return;
}
res[rt].add += add;
res[rt].Max += (long long)add*(2*R-1);
res[rt].sum += (long long)add*(L+R-1)*(R-L+1);
}
void pushdown(int rt,int L,int R)
{
if(res[rt].cov || res[rt].add)
{
if(!res[rt].lc)
res[rt].lc=++cnt;
if(!res[rt].rc)
res[rt].rc=++cnt;
int mid=(L+R)/2;
Add(res[rt].lc,L,mid,res[rt].cov,res[rt].add);
Add(res[rt].rc,mid+1,R,res[rt].cov,res[rt].add);
res[rt].cov=res[rt].add=0;
}
}
void update(int& rt,int l,int r,int ql,int qr,int k)
{
if(!rt)
rt=++cnt;
if(ql<=l && r<=qr)
{
Add(rt,l,r,k,0);
return;
}
pushdown(rt,l,r);
int mid=(l+r)/2;
if(ql<=mid)
update(res[rt].lc,l,mid,ql,qr,k);
if(mid+1<=qr)
update(res[rt].rc,mid+1,r,ql,qr,k);
pushup(rt);
}
long long query_sum(int rt,int l,int r,int ql,int qr)
{
if(!rt)
return 0;
if(ql<=l && r<=qr)
return res[rt].sum;
pushdown(rt,l,r);
int mid=(l+r)/2;
long long ans=0;
if(ql<=mid)
ans += query_sum(res[rt].lc,l,mid,ql,qr);
if(mid+1<=qr)
ans += query_sum(res[rt].rc,mid+1,r,ql,qr);
return ans;
}
int query_greater(int rt,int l,int r,int val)
{
if(res[rt].Max<val)
return 0;
if(l==r)
return l;
pushdown(rt,l,r);
int mid=(l+r)/2,lans=query_greater(res[rt].lc,l,mid,val);
return lans?lans:query_greater(res[rt].rc,mid+1,r,val);
}
int main()
{
freopen("1.in","r",stdin);
int n,m;
cin >> n >> m;
for(int i=1;i<=m;i++)
scanf("%d",&c[i]);
int q;
cin >> q;
for(int i=1;i<=q;i++)
{
int x,y;
scanf("%d %d",&x,&y);
que[y].push_back(make_pair(x,i));
}
root=1, cnt=1;
for(int i=1;i<=m;i++)
{
Add(root,1,n,0,1); //直接全局+等差数列
int pos=query_greater(root,1,n,c[i]);
if(pos)
update(root,1,n,pos,n,c[i]);
for(auto x:que[i])
ans[x.second]=query_sum(root,1,n,1,x.first);
}
for(int i=1;i<=q;i++)
printf("%lld\n",ans[i]-1);
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
5 4 1 100 100 20 20 1 1 2 1 3 1 4 1 5 1 1 2 2 2 3 2 4 2 5 2 1 3 2 3 3 3 4 3 5 3 1 4 2 4 3 4 4 4 5 4
output:
result:
Test #2:
score: 0
Time Limit Exceeded
input:
2000 2000 1 1 1 1 1 1 1 5 1 2 1 1 4 1 8 1 1 1 11 7 32 28 3 37 41 48 48 32 31 55 17 40 64 65 48 32 61 46 56 72 116 59 90 44 61 54 64 136 118 60 130 98 146 154 124 144 130 63 148 148 137 122 230 199 239 148 214 235 257 262 188 276 210 224 276 201 295 262 162 225 280 310 279 308 311 383 325 312 265 445...
output:
result:
Test #3:
score: 0
Time Limit Exceeded
input:
2000 2000 1 1 1 1 1 1 1 3 1 8 1 1 5 7 1 4 1 8 14 8 40 1 30 16 33 30 23 28 2 24 31 52 4 24 49 1 4 50 10 50 103 82 92 84 55 45 62 100 80 125 131 117 94 143 65 124 63 104 69 76 226 146 131 161 239 246 160 178 254 209 248 242 201 196 208 161 225 222 187 279 389 370 298 274 322 275 333 293 435 355 359 33...
output:
result:
Test #4:
score: 0
Time Limit Exceeded
input:
1000000000 200000 3 1000000000 999990893 999990333 999985081 999977767 999972028 999967702 999964821 999957604 999954630 999951759 999945888 999944174 999936290 999926683 999921422 999917746 999917576 999917453 999915840 999910322 999906639 999899755 999898806 999893506 999892205 999889172 999888546...
output:
result:
Test #5:
score: 0
Time Limit Exceeded
input:
1000000000 200000 3 1000000000 999995224 999994164 999984251 999978283 999977190 999977136 999971754 999962090 999954077 999953337 999944089 999941723 999934697 999928129 999918274 999916802 999911461 999904873 999896738 999894431 999893134 999890460 999882614 999875616 999872423 999864204 999861303...
output:
result:
Test #6:
score: 0
Time Limit Exceeded
input:
1000000000 200000 3 1000000000 999991486 999981766 999976784 999971384 999967247 999962605 999954863 999952245 999944446 999935072 999933232 999926866 999926508 999917163 999912995 999911320 999910282 999902994 999897400 999891313 999884031 999879635 999872168 999868782 999862129 999858324 999849475...
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
1000000000 200000 3 1000000000 999990957 999983325 999978919 999976605 999971359 999966791 999960902 999953591 999948715 999939237 999933153 999927901 999927473 999918348 999913133 999908978 999905504 999897688 999890236 999889555 999881171 999876934 999869706 999861968 999856787 999856139 999849944...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
1000000000 200000 3 1000000000 999997864 999994431 999988155 999986495 999980513 999979440 999971737 999968982 999962950 999953596 999952790 999948751 999948220 999939491 999939481 999933726 999928543 999926861 999921112 999914865 999914690 999905547 999901263 999892611 999890346 999885103 999877902...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
200000 200000 836928809 731939461 556788044 353546603 350398812 565254149 593555454 606090526 74539453 169606212 264614251 529671433 344082061 270428180 97052708 49681369 774482819 203896331 803868124 27181273 123894022 479228608 89591553 525765979 568328479 204369020 739500845 253785869 442847289 4...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
200000 200000 704607471 790824111 684887531 350919959 584747303 684505378 887235108 764616054 1233483 783787575 632548936 958638409 241975493 209675206 179696995 232207356 255754212 548391298 902555004 531412974 394766213 652334186 179826409 798430222 976469763 221361857 791029133 313795280 63409822...
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
200000 200000 1 2 5 10 17 26 37 50 65 82 101 122 145 170 197 226 257 290 325 362 401 442 485 530 577 626 677 730 785 842 901 962 1025 1090 1157 1226 1297 1370 1445 1522 1601 1682 1765 1850 1937 2026 2117 2210 2305 2402 2501 2602 2705 2810 2917 3026 3137 3250 3365 3482 3601 3722 3845 3970 4097 4226 4...
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 21 5 23 13 3 19 1 8 30 24 20 7 26 26 36 21 30 22 65 68 84 45 53 64 62 87 69 76 98 72 63 73 79 93 59 100 59 102 135 170 176 176 151 134 184 150 187 183 171 178 165 212 157 154 155 194 229 230 318 304 303 320 289 270 261 294 273 280 296 331 302...
output:
result:
Test #13:
score: 0
Time Limit Exceeded
input:
200000 200000 1 1 1 1 2 3 4 1 5 1 1 10 1 1 1 1 1 8 5 18 33 11 40 4 2 38 1 3 45 37 60 15 55 41 16 45 53 33 28 18 57 93 73 104 119 84 66 109 66 50 82 91 65 91 102 159 77 119 69 62 239 144 227 145 139 143 174 151 261 223 256 148 144 153 169 199 290 261 265 271 325 344 327 334 359 315 276 360 424 283 38...
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
200000 200000 1 4 1 12 16 1 9 10 27 24 35 1 1 28 12 12 35 58 1 75 8 27 105 95 26 22 121 76 73 55 138 49 33 31 128 3 52 48 42 137 91 115 180 119 216 197 263 238 178 222 136 242 105 80 183 209 287 134 62 249 253 299 136 141 144 227 302 321 276 139 400 484 419 270 422 330 325 533 184 360 482 345 492 48...
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
200000 200000 1 5 3 11 22 18 41 37 63 24 1 73 70 48 76 56 37 55 17 1 135 14 148 205 94 93 210 84 120 276 48 168 44 21 84 250 184 147 293 135 143 375 189 267 387 84 78 127 454 305 396 87 455 111 87 238 540 328 257 178 190 443 434 584 568 589 697 190 494 521 668 600 567 614 782 321 778 832 325 902 307...
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
1000000000 200000 966277270 179221972 147871083 903511077 5002193 325361583 742605361 991535375 455636173 843251280 957709410 611724610 663453854 198526499 55570910 922042601 133801610 589927857 886621380 774136032 202722685 731857077 592182750 65486957 337337023 985393628 78916532 821319946 6635752...
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
1000000000 200000 1 2 5 10 17 26 37 50 65 82 101 122 145 170 197 226 257 290 325 362 401 442 485 530 577 626 677 730 785 842 901 962 1025 1090 1157 1226 1297 1370 1445 1522 1601 1682 1765 1850 1937 2026 2117 2210 2305 2402 2501 2602 2705 2810 2917 3026 3137 3250 3365 3482 3601 3722 3845 3970 4097 42...
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
1000000000 200000 1 1 59 88 50 13 185 246 36 1 277 151 405 37 502 333 97 136 399 54 51 360 156 102 281 757 159 923 481 577 185 949 555 860 860 918 937 1206 1037 333 1312 583 788 519 568 743 404 796 1753 370 260 902 1845 1951 711 653 125 75 1618 1770 368 1798 990 304 673 1663 1593 1675 1926 2363 245 ...
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
1000000000 200000 1 25 18 108 169 26 204 319 43 236 370 311 166 323 485 606 276 783 844 514 391 599 846 90 217 1116 1043 1036 1392 1257 161 291 1346 565 542 871 18 126 1900 1764 1579 1494 1572 803 385 1105 155 780 2160 1223 2109 2573 939 855 1424 719 2681 1239 1886 114 1753 1593 2869 1313 872 1899 2...
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
1000000000 200000 1 4 26 1 16 178 201 169 127 83 548 330 166 581 685 406 275 968 918 238 93 586 750 1026 560 1301 1048 1708 1759 595 1666 1145 1674 774 517 130 1553 1323 216 1213 2166 735 1878 797 2518 168 3008 1007 365 488 937 2017 1512 876 203 3333 397 3443 2427 1998 3261 2855 1008 2226 1215 1864 ...