QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378158 | #8567. Cheap Construction | ucup-team2894# | WA | 144ms | 13884kb | C++20 | 1.7kb | 2024-04-06 08:28:31 | 2024-04-06 08:28:31 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;
using pii = pair<int,int>;
using ll = long long;
using pll = pair<ll,ll>;
using vi = vector<int>;
using ld = long double;
#define all(x) (x).begin(), (x).end()
const int maxn = 1e6+10, inf = 1e9+100;
const ll linf = 1e18+100;
const int mod = 1e9+7;
const ld eps = 1e-9;
const ld PI = acos(-1.L);
int bit[maxn];
void upd(int a,int b){
for(;a<maxn;a+=a&-a)bit[a]+=b;
}
int qu(int a){
int b=0;
for(;a;a-=a&-a)b+=bit[a];
return b;
}
pii seg[maxn * 2];
int n;
pii qu(int l,int r) {
pii ans = {inf,inf};
l+=n,r+=n;
while(l<=r){
if(l&1)ans=min(ans,seg[l]),l++;
if(!(r&1))ans=min(ans,seg[r]),r--;
l>>=1;r>>=1;
}
return ans;
}
int a[maxn], b[maxn];
int v[maxn];
vector<pii> ans;
void rec(int l,int r){
if(r<l)return;
auto [v,ind] = qu(l,r);
// cerr << l << " " << r << " " << ind << endl;;
ind *= -1;
ans.push_back({l,v});
rec(l,ind-1);
rec(ind+1,r);
}
void solvee(){
cin >> n;
for(int i=0;i<=n;i++)bit[i]=a[i]=b[i]=v[i]=0;
ans.clear();
for(int i=0;i<=2*n;i++)seg[i]={0,0};
for(int i = 0;i<n;i++){
cin >> a[i] >> b[i];
}
for(int i=1;i<=n;i++)upd(i,1);
for(int i=n-1;i>=0;i--){
v[qu(a[i])] = b[i];
upd(a[i],1);
}
for(int i=1;i<=n;i++){
seg[n+i] = {v[i],-i};
}
for(int i=n;i>=1;i--){
seg[i] = min(seg[2*i],seg[2*i+1]);
}
ans.clear();
rec(1,n);
for(auto [a,b] : ans) {
cout << a << " " << b << "\n";
}
}
void solve(){
int tc;
cin >> tc;
while(tc--){
solvee();
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout<<fixed;
cout.precision(20);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13876kb
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: 2ms
memory: 13884kb
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: -100
Wrong Answer
time: 144ms
memory: 11940kb
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 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ...
result:
wrong answer 1st lines differ - expected: '1 2', found: '1 0'