QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#122825#6192. Interval ProblemWolamWA 38ms23716kbC++14988b2023-07-11 11:45:522023-07-11 11:45:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-11 11:45:52]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:23716kb
  • [2023-07-11 11:45:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,l[200005],r[200005];
int p[400005],sum[400005];
int ans[200005];
int h[400005],g[400005],f[400005];
void sol()
{
	memset(p,0x3f,sizeof(p));
	memset(sum,0,sizeof(sum));
	for(int i=1;i<=n;i++)
	{
		p[r[i]]=l[i];
		sum[r[i]]++;
	}
	for(int i=1;i<=n+n;i++)
		sum[i]+=sum[i-1];
	for(int i=n+n;i>=1;i--)
		p[i]=min(p[i],p[i+1]);
	for(int i=1;i<=n+n;i++)
	{
		if(p[i]>=i)
		{
			g[i]=i;
			f[i]=h[i]=0;
		}
		else
		{
			g[i]=g[p[i]];
			h[i]=h[p[i]]+1;
			f[i]=sum[i-1]+f[p[i]];
		}
	}
	for(int i=1;i<=n;i++)
	{
		int x=p[l[i]];
		ans[i]+=f[l[i]];
		ans[i]-=sum[g[x]-1]*(h[l[i]]);
	}
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>l[i]>>r[i],ans[i]=n-1;
	sol();
	for(int i=1;i<=n;i++)
	{
		l[i]=n+n+1-l[i];
		r[i]=n+n+1-r[i];
		swap(l[i],r[i]);
	}
	sol();
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 17756kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

7
5
4
5
5

result:

ok 5 number(s): "7 5 4 5 5"

Test #2:

score: -100
Wrong Answer
time: 38ms
memory: 23716kb

input:

200000
342504 342505
248314 248317
259328 259334
234817 234821
225726 225732
371424 371425
260562 260565
34752 34753
132098 132100
262130 262134
7254 7255
228491 228492
43488 43492
188408 188410
11691 11692
350334 350335
327350 327352
360684 360685
182051 182052
72131 72135
194666 194668
61303 61313...

output:

200005
200012
200008
200001
200005
200023
199999
199999
199999
200009
200002
199999
200012
200009
200002
200004
199999
200010
200005
200002
199999
200002
199999
199999
199999
199999
200021
200023
200013
200000
199999
199999
200010
200013
200008
200003
200015
200003
200001
200002
199999
200006
200006...

result:

wrong answer 1st numbers differ - expected: '12', found: '200005'