QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479735#8567. Cheap Constructionucup-team3519#WA 140ms17968kbC++202.1kb2024-07-15 20:37:032024-07-15 20:37:04

Judging History

你现在查看的是最新测评结果

  • [2024-07-15 20:37:04]
  • 评测
  • 测评结果:WA
  • 用时:140ms
  • 内存:17968kb
  • [2024-07-15 20:37:03]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
const int N=500005;
const ll mod=998244353;
ll qpow(ll a,ll b){
	ll ans=1;
	if(b==0)
	return 1;
	if(b%2)
	ans=a;
	ll t=qpow(a,b/2);
	return t*t%mod*ans%mod;
}
ll inv(ll a){
	return qpow(a,mod-2);
}
struct pt{
	ll num;
	ll plc;
};
int cmp(pt a,pt b){
	if(a.num==b.num)return a.plc>b.plc;
	return a.num<b.num;
}
pt min(pt a,pt b){
	if(cmp(a,b))return a;
	else return b;
}
const int MN=N*4;
struct BIT{
    vector<int>old;
    int fenT[MN];
    void add(int x,int d) {while(x<MN) {fenT[x]+=d,old.push_back(x);x+=x&(-x);}}
    void add(int l,int r,int d) {add(l,d);add(r+1,-d);}
    int query(int x) {int ans=0;while(x>=1) {ans+=fenT[x];x-=x&-x;}return ans;}
    int query(int l,int r) {if(r<l)return 0;return query(r)-query(l-1);}
    void clear() {for(auto p: old) fenT[p]=0;old.clear();}
}bt;
pt f[N][25];
pt b[N];
int lg[N];
void stinit(ll n){
	lg[1]=0;
	for(int i=2;i<=n;i++){
		lg[i]=lg[i>>1]+1;
	} 
	for(int i=1;i<=n;i++){
		f[i][0]=b[i];
	}
	for(int j=1;j<=lg[n];j++){
		for(int i=1;i<=n-(1<<j)+1;i++){
			f[i][j]=min(f[i][j-1],f[i+(1<<(j-1))][j-1]);
		}
	}
}
pt stfind(ll x,ll y){
	ll p=lg[y-x+1];
	return min(f[x][p],f[y-(1<<p)+1][p]);
}
ll a[N];
vector<pt>ans;
int cnt=1;


void calc(ll l,ll r){
	if(r-l+1<=0)return;
	ll p=stfind(l,r).plc;
	ans.push_back({cnt,a[p]});
	calc(l,p-1);
	cnt++;
	calc(p+1,r);
}
void op(){
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].num<<' '<<ans[i].plc<<'\n';
	}
}
pt sg[N];
void solve(){
	ll n;
	cin>>n;
	bt.clear();
	
	for(int i=1;i<=n;i++){
		bt.add(i,i,i);
	}
	for(int i=1;i<=n;i++){
		cin>>sg[i].plc>>sg[i].num;
	}
	for(int i=n;i>=1;i--){
		
		int p=bt.query(sg[i].plc);
		bt.add(sg[i].plc,n,1);
		a[p]=sg[i].num;
	}
	//for(int i=1;i<=n;i++)cout<<a[i]<<' ';
	for(int i=1;i<=n;i++){
		b[i]={a[i],i};
	}
	
	ans.clear();
	cnt=1;
	stinit(n);
	calc(1,n);	
	
	op();
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int t0;
	cin>>t0;
	for(int t=0;t<t0;t++){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 15912kb

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: 17968kb

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: 140ms
memory: 16092kb

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'