QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378775 | #8567. Cheap Construction | ucup_team_qiuly# | WA | 1ms | 4104kb | C++14 | 2.4kb | 2024-04-06 14:36:12 | 2024-04-06 14:36:12 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
int t,n,p[500005],h[500005];
namespace SGT{
int tree[1048576];
void build(int now,int nowl,int nowr){
tree[now]=nowr-nowl+1;
if (nowl==nowr)return;
int mid=(nowl+nowr)/2;
build(now*2,nowl,mid);
build(now*2+1,mid+1,nowr);
return;
}
int find(int now,int nowl,int nowr,int k){
if (nowl==nowr)return nowl;
int mid=(nowl+nowr)/2;
if (k<=tree[now*2])return find(now*2,nowl,mid,k);
return find(now*2+1,mid+1,nowr,k-tree[now*2]);
}
void del(int now,int nowl,int nowr,int x){
tree[now]--;
if (nowl==nowr)return;
int mid=(nowl+nowr)/2;
if (x<=mid)del(now*2,nowl,mid,x);
else del(now*2+1,mid+1,nowr,x);
return;
}
}
int a[500005];
namespace ST{
int log_2[500005],f[20][500005];
void init(){
for (int i=2;i<=n;i++)log_2[i]=log_2[i/2]+1;
for (int i=1;i<=n;i++)f[0][i]=i;
for (int i=1;i<20;i++)
for (int j=1;j+(1<<i)-1<=n;j++){
if (a[f[i-1][j]]<a[f[i-1][j+(1<<(i-1))]])f[i][j]=f[i-1][j];
else f[i][j]=f[i-1][j+(1<<(i-1))];
}
return;
}
int ask(int l,int r){
int w=log_2[r-l+1];
if (f[w][l]<f[w][r-(1<<w)+1])return f[w][l];
return f[w][r-(1<<w)+1];
}
}
namespace BIT{
int tree[500005];
void init(){
for (int i=1;i<=n;i++)tree[i]=0;
return;
}
void add(int p){
while(p<=n)tree[p]++,p+=(p&(-p));
return;
}
int ask(int p){
int ans=0;
while(p)ans+=tree[p],p-=(p&(-p));
return ans;
}
}
int main(){
cin>>t;
while(t--){
scanf("%d",&n);
for (int i=1;i<=n;i++)scanf("%d%d",&p[i],&h[i]);
SGT::build(1,1,n);
for (int i=n;i>=1;i--){
int x=SGT::find(1,1,n,p[i]);
a[x]=h[i];
SGT::del(1,1,n,x);
}
set<int> qwq;
qwq.insert(n+1);
int x=1;
ST::init();
BIT::init();
for (int i=1;i<=n;i++){
while(qwq.find(x)!=qwq.end())x++;
int y=(*qwq.lower_bound(x))-1;
int p=ST::ask(x,y);
printf("%d %d\n",BIT::ask(p)+1,a[p]);
BIT::add(p);
qwq.insert(p);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3800kb
input:
1 3 1 1 2 2 1 3
output:
1 1 1 3 3 2
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4104kb
input:
2 3 1 1 1 2 3 1 3 1 3 2 1 3 3
output:
1 1 1 2 3 1 1 1 1 3 3 3
result:
wrong answer 2nd lines differ - expected: '1 1', found: '1 2'