QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379116#8567. Cheap Constructionucup-team191#WA 0ms18024kbC++231.4kb2024-04-06 16:14:592024-04-06 16:15:00

Judging History

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

  • [2024-04-06 16:15:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:18024kb
  • [2024-04-06 16:14:59]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=500010,MOD=1e9+7,M=1<<19;
const char en='\n';
const ll LLINF=1ll<<60;

int t,n,seg1[M*2+10],p[N],he[N],h[N];
pii seg2[M*2+10];

void upd1(int i,int x)
{
	seg1[i+=M]=x;
	for (i/=2;i;i/=2) seg1[i]=seg1[i*2]+seg1[i*2+1];
}

int getk(int k)
{
	if (k==0) return -1;
	int i=1;
	while (i<M)
	{
		if (seg1[i*2]>=k) i=i*2;
		else k-=seg1[i*2],i=i*2+1;
	}
	return i-M;
}

void upd2(int i,int x)
{
	seg2[i+=M]={x,i};
	for (i/=2;i;i/=2) seg2[i]=min(seg2[i*2],seg2[i*2+1]);
}

pii ge(int l,int r,int lo=0,int hi=M,int i=1)
{
	if (lo>=l && hi<=r) return seg2[i];
	if (lo>=r || hi<=l) return {MOD,MOD};
	int mid=(lo+hi)/2;
	return min(ge(l,r,lo,mid,i*2),ge(l,r,mid,hi,i*2+1));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	while (t--)
	{
		cin>>n;
		for (int i=0;i<n;++i) cin>>p[i]>>he[i],upd1(i,1);
		upd1(n,1);
		for (int i=n-1;i>=0;--i)
		{
			int ind=getk(p[i]);
			upd1(ind,0);
			upd2(ind,he[i]);
			h[ind]=he[i];
		}
		int cup=0;
		for (int i=0;i<n;++i)
		{
			int l=getk(cup),r=getk(cup+1);
			while (r==l+1)
			{
				++cup;
				l=r;
				r=getk(cup+1);
			}
			pii re=ge(l+1,r);
			cout<<cup+1<<' '<<re.x<<en;
			upd1(re.y,1);
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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'