QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378932 | #8567. Cheap Construction | ucup-team135# | TL | 851ms | 13800kb | C++20 | 1.3kb | 2024-04-06 15:18:08 | 2024-04-06 15:18:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#else
#define debug(...)
#endif
#ifdef LOCAL
#define __int128 long long
#endif // LOCAL
const int maxn=5e5+5;
int sp[maxn][20];
vector<int> a;
vector<pair<int,int> > res;
int f(int pos1,int pos2)
{
return a[pos1]<a[pos2] ? pos1 : pos2;
}
int get(int l,int r)
{
int o=31-__builtin_clz(r-l);
return f(sp[l][o],sp[r-(1<<o)][o]);
}
void solve(int l,int r)
{
if(l==r) return;
int pos=get(l,r);
res.app({l,a[pos]});
solve(l,pos);solve(pos+1,r);
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--)
{
int n;cin>>n;a.clear();
for(int i=0;i<n;++i) {int pos,x;cin>>pos>>x;--pos;a.insert(a.begin()+pos,x);}
for(int i=0;i<n;++i) {sp[i][0]=i;}
for(int j=1;j<20;++j)
{
for(int i=0;i<=n-(1<<j);++i)
{
sp[i][j]=f(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
}
}
res.clear();
solve(0,n);
for(auto [x,y]:res) cout<<x+1<<' '<<y<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
1 3 1 1 2 2 1 3
output:
1 1 1 3 3 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
2 3 1 1 1 2 3 1 3 1 3 2 1 3 3
output:
1 1 1 1 1 2 1 1 1 3 3 3
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 78ms
memory: 3692kb
input:
1000 500 1 25 2 115 2 356 4 396 5 417 3 416 1 376 8 302 5 475 8 134 5 470 2 191 9 443 9 483 7 311 6 415 14 422 6 288 9 411 9 318 18 406 20 213 16 292 8 351 8 150 20 199 3 311 22 321 22 221 16 364 7 316 17 79 23 160 23 369 6 209 36 9 35 490 2 498 30 391 31 175 10 322 16 484 4 63 44 304 39 300 13 309 ...
output:
1 2 1 2 1 40 1 68 3 65 3 86 5 68 5 301 5 376 5 459 8 498 10 81 10 102 10 258 12 180 13 474 14 482 17 6 17 6 17 6 17 6 17 15 17 15 18 108 18 229 20 197 21 466 23 48 23 57 23 227 23 252 23 393 25 382 27 267 29 58 29 66 30 168 30 191 30 252 31 263 31 432 33 375 35 242 36 275 36 400 39 393 41 368 43 55 ...
result:
ok 500000 lines
Test #4:
score: 0
Accepted
time: 87ms
memory: 3820kb
input:
1000 500 1 73 1 297 1 133 3 384 5 303 1 456 7 14 3 220 1 225 6 387 6 248 11 74 8 459 4 344 11 181 16 493 14 58 7 492 5 486 6 225 3 20 1 167 11 375 4 95 22 13 2 455 14 335 18 260 3 46 11 373 19 433 8 61 7 321 14 197 5 47 13 295 6 206 19 428 15 474 28 183 26 482 22 308 33 235 24 247 39 119 5 426 44 15...
output:
1 3 1 3 1 3 1 3 1 26 1 46 1 100 1 156 1 220 1 278 2 345 4 444 7 112 8 140 8 142 8 167 8 202 9 266 9 363 9 368 12 347 15 248 15 344 16 457 18 455 19 457 22 137 22 206 24 170 25 176 25 253 25 461 28 225 28 264 31 100 31 181 31 211 33 268 34 293 36 251 36 257 37 312 39 259 41 217 43 4 43 4 43 88 43 383...
result:
ok 500000 lines
Test #5:
score: 0
Accepted
time: 124ms
memory: 6632kb
input:
100 5000 1 2671 1 1099 3 2196 1 1009 2 297 3 3844 6 401 2 3199 8 1568 3 1435 6 2257 7 4299 5 2315 12 1425 6 1279 11 527 11 100 12 1495 13 2892 17 4548 16 348 10 4847 19 4320 24 2610 20 468 24 320 2 1764 4 307 20 1045 19 797 17 2185 25 4368 28 1560 29 1366 7 3490 2 3177 16 3805 33 1092 32 2461 7 1624...
output:
1 1 1 1 1 4 1 70 1 98 1 141 1 246 1 424 1 540 1 2075 1 3886 3 3267 5 577 5 1244 6 3014 8 1373 8 1414 8 1974 10 1599 10 2841 11 3104 12 3957 13 4824 13 4832 16 2416 16 4830 20 433 20 2022 20 3135 21 3843 21 4098 21 4157 25 2344 26 3672 29 928 29 1009 29 1089 29 1276 30 1755 30 4833 32 2242 33 3330 34...
result:
ok 500000 lines
Test #6:
score: 0
Accepted
time: 194ms
memory: 6640kb
input:
50 10000 1 7404 1 7552 3 4284 1 1500 5 1792 5 9068 4 8275 8 2357 7 469 10 3006 10 1191 6 8805 6 2704 2 2505 12 1435 16 4993 13 6359 9 9779 12 7254 15 9694 6 6990 9 6849 22 8155 4 4241 10 5531 22 6487 27 368 20 1664 13 5218 25 6795 23 8778 20 4142 4 8584 4 8738 24 9167 22 706 17 1860 23 96 23 8338 1 ...
output:
1 1 1 8 1 9 1 15 1 54 1 73 1 163 1 1332 1 1704 1 3089 1 3943 1 4310 3 7827 5 3956 6 4384 9 1791 9 3853 9 8926 10 9723 12 3940 12 6230 12 7278 15 5840 17 5623 19 327 19 518 19 682 19 3472 21 7173 23 733 23 1393 23 1825 24 6029 24 7361 24 7568 25 8146 25 8171 28 9323 31 2016 31 3460 31 4840 32 5262 34...
result:
ok 500000 lines
Test #7:
score: 0
Accepted
time: 190ms
memory: 6976kb
input:
50 10000 1 6249 2 7029 2 357 4 5488 5 8678 4 6108 4 7813 3 274 1 8027 8 9951 1 8969 3 484 1 1424 7 7366 15 8602 10 5263 12 9791 17 7083 14 4625 12 4396 7 5105 16 4007 6 1943 7 8485 24 1293 8 5539 5 9189 8 8898 23 1839 20 7303 4 9396 11 4124 17 9950 19 2158 15 6493 30 7789 31 7075 8 8527 30 8921 38 8...
output:
1 2 1 2 1 4 1 13 1 18 1 26 1 59 1 1444 1 7473 2 7688 4 3355 5 7257 7 74 7 160 7 551 7 581 7 2095 7 2096 7 4395 8 6351 8 8765 11 2704 11 8388 12 8787 14 3874 14 7481 18 856 18 2742 19 3115 19 7339 21 3362 21 3378 23 3365 23 3457 23 4182 23 6319 24 6972 25 8496 27 5518 30 4197 30 6809 31 8946 33 7183 ...
result:
ok 500000 lines
Test #8:
score: 0
Accepted
time: 446ms
memory: 9732kb
input:
20 25000 1 14368 1 2826 3 9715 3 21430 3 11764 3 18927 4 717 4 7994 8 714 3 20485 4 284 9 4884 3 1481 7 3493 8 13233 16 10004 9 14771 8 2152 3 21774 5 15884 7 23464 3 5911 10 4643 15 23716 24 15579 13 9227 20 6401 18 5182 11 10155 21 2709 6 17801 2 7562 28 1618 29 10438 29 19637 26 8946 1 24856 24 2...
output:
1 1 1 1 1 11 1 30 1 36 1 74 1 3399 1 3871 1 18960 1 24862 4 6535 4 12331 6 8818 7 19408 9 13481 9 14168 9 16179 13 86 13 89 13 98 13 459 13 7807 13 14615 13 18972 15 22440 17 20692 19 4989 19 5041 19 16776 21 7249 21 16340 21 20637 24 7384 25 10163 26 10477 26 22767 28 21458 30 7073 30 7193 30 7831 ...
result:
ok 500000 lines
Test #9:
score: 0
Accepted
time: 851ms
memory: 13800kb
input:
10 50000 1 40899 1 19858 2 37315 4 42990 4 42688 1 26367 2 3168 5 44653 8 26177 3 48486 7 20434 1 38766 5 32760 2 39034 13 42875 11 17508 15 41766 17 44586 1 2602 6 46879 16 3259 9 41465 9 8482 24 8129 22 32793 15 18406 18 30914 13 6106 8 17153 4 18147 7 46909 19 140 33 26355 34 42241 25 37395 11 46...
output:
1 1 1 1 1 3 1 6 1 9 1 19 1 23 1 25 1 29 1 55 1 65 1 2285 1 41147 3 3925 3 3972 3 7107 3 8573 3 8876 3 11260 3 33245 3 33479 5 36962 7 35348 7 37973 10 12203 12 30296 13 45376 13 48426 18 29311 20 163 20 326 20 666 20 746 20 8616 20 13582 21 20683 23 16518 25 5337 25 13147 25 18494 26 21305 26 21740 ...
result:
ok 500000 lines
Test #10:
score: -100
Time Limit Exceeded
input:
2 250000 1 166085 2 52706 2 51784 3 23379 2 209734 1 191492 5 119361 4 137 1 131744 9 161929 7 62827 9 238737 10 84433 7 67633 6 69366 1 105069 4 194861 9 74477 11 214963 8 9757 5 149316 15 182750 22 42579 11 150931 15 88679 3 36229 13 6440 11 236704 7 164790 1 139475 24 172162 9 219844 13 171219 21...
output:
1 1 1 3 1 9 1 11 1 108 1 154 1 1417 1 1755 1 43281 1 94395 1 124308 3 187673 5 49048 5 144033 6 192250 7 231652 9 137838 9 168540 9 182410 13 7599 13 20846 13 40830 13 51999 13 54448 13 59654 13 150698 14 186587 14 189535 15 207779 15 227140 18 243882 20 160546 20 220045 22 219925 25 144884 25 14766...