QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673615#9228. ICPC Inferenceucup-team191#WA 68ms62704kbC++234.1kb2024-10-25 02:08:402024-10-25 02:08:40

Judging History

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

  • [2024-10-25 02:08:40]
  • 评测
  • 测评结果:WA
  • 用时:68ms
  • 内存:62704kb
  • [2024-10-25 02:08:40]
  • 提交

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=4200010,MOD=1e9+7,M=1<<23;
const char en='\n';
const ll LLINF=1ll<<60;

int n,d,l,seg[M*2+10];
vi subs[N];

void upd(int i,int x)
{
	for (i+=M;i;i/=2) seg[i]+=x;
}

int ge(int l,int r,int lo=0,int hi=M,int i=1)
{
	if (lo>=l && hi<=r) return seg[i];
	if (lo>=r || hi<=l) return 0;
	int mid=(lo+hi)/2;
	return 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>>n>>d>>l;
	for (int i=0;i<n;++i)
	{
		int j,x;
		cin>>j>>x;
		--j;
		subs[j].pb(x);
	}
	ll c1=0,c2=0,c3=0;
	for (int i=0;i<d;++i)
	{
		if (subs[i].size()>=3) ++c3;
		if (subs[i].size()>=2) ++c2;
		if (subs[i].size()>=1) ++c1;
	}
	ll an=c1*c2*c3-c3*c1-2*c3*c2-2*c3;
	//>=3, 1, >=1
	{
		vi maxp,maxp3;
		for (int i=0;i<d;++i) if (subs[i].size()>=1)
		{
			maxp.pb(subs[i].back()+20*(subs[i].size()-1));
			if (subs[i].size()>=3)
			{
				maxp3.pb(subs[i].back()+20*(subs[i].size()-1));
			}
		}
		sort(all(maxp));
		sort(all(maxp3));
		for (int i=0;i<d;++i) if (subs[i].size()==1)
		{
			int cv=maxp.end()-lower_bound(all(maxp),subs[i][0])-1;
			int cv3=maxp3.end()-lower_bound(all(maxp3),subs[i][0]);
			an+=c3*cv-cv3;
		}
	}
	//2, x, >=1
	{
		vector<pii> slo; //2 slowest, 1 fastest
		for (int i=0;i<d;++i) if (subs[i].size()>=2)
		{
			int sz=subs[i].size();
			slo.pb({subs[i][sz-1]+subs[i][sz-2]+(sz-2)*20,subs[i][0]});
		}
		sort(all(slo));
		vi min1,pen1;
		for (int i=0;i<d;++i) if (subs[i].size()>=1)
		{
			int sz=subs[i].size();
			min1.pb(subs[i][sz-1]+20*(sz-1));
			if (sz==1) pen1.pb(subs[i][0]);
		}
		sort(all(min1));
		sort(all(pen1));
		vl prefs;
		prefs.pb(0);
		for (auto x: slo) prefs.pb(prefs.back()+(min1.end()-lower_bound(all(min1),x.y))-1);
		ll s1=0;
		for (int i=0;i<d;++i) if (subs[i].size()==1) s1+=min1.end()-lower_bound(all(min1),subs[i][0])-1;
		vector<vi> pit(prefs.size());
		for (int i=0;i<d;++i) if (subs[i].size()==2)
		{
			int sz=2;
			//2, 2, 1
			int x=lower_bound(all(slo),pii(subs[i][0]+subs[i][1],0))-slo.begin();
			an+=(c2-x-1)*(c1-2);
			//2, not 2, 1
			an+=prefs[x]; //subtract how many in first x have .second<=subs[i][sz-1]+20*(sz-1) later!
			pit[x].pb(subs[i][sz-1]+20*(sz-1));
			//cout<<an<<' '<<s1<<' '<<upper_bound(all(pen1),subs[i][sz-1]+20*(sz-1))-pen1.begin()<<en;
			an+=s1-(upper_bound(all(pen1),subs[i][sz-1]+20*(sz-1))-pen1.begin()); //subtract how many 1s have penalty<=subs[i][sz-1]+20*(sz-1)
		}
		for (int i=0;i<=(int)slo.size();++i)
		{
			for (auto x: pit[i]) an-=ge(0,x+1);
			if (i<(int)slo.size()) upd(slo[i].y,1);
		}
	}
	//cout<<an<<en;
	//1, >=1, >=1
	{
		vi maxps,p1;
		for (int i=0;i<d;++i) if (subs[i].size()>=1)
		{
			int sz=subs[i].size();
			maxps.pb(subs[i].back()+20*(sz-1));
			if (sz==1) p1.pb(subs[i][0]);
		}
		sort(all(maxps));
		sort(all(p1));
		vi gr(N),gl(N);
		gl[N-1]=c1;
		for (int i=N-2;i>=0;--i)
		{
			gl[i]=gl[i+1];
			while (gl[i] && maxps[gl[i]-1]>=i) --gl[i];
		}
		for (int i=0;i<N;++i) gl[i]=c1-gl[i];
		int p1s=p1.size();
		for (int i=1;i<N;++i)
		{
			gr[i]=gr[i-1];
			while (gr[i]<p1s && p1[gr[i]]<=i) ++gr[i];
		}
		vi nap(N);
		for (int i=0;i<d;++i) if (subs[i].size()>=1)
		{
			int lmi=subs[i][0],lma=subs[i][0],sz=subs[i].size();
			int lar=gr[subs[i][0]];
			ll cu=lar*1ll*gl[subs[i][0]];
			for (int j=1;j<sz;++j)
			{
				if (lma<subs[i][j])
				{
					for (int k=lmi;k<=lma;++k) if (nap[k])
					{
						int nl=gl[k],nr=gr[k];
						cu+=(nr-lar)*1ll*nl;
					}
					lmi=subs[i][j];
				}
				for (int k=subs[i][j]+20*j;k>=subs[i][j];k-=20) if (!nap[k]) nap[k]=1;
				else break;
				lma=subs[i][j]+20*j;
			}
			for (int k=lmi;k<=lma;++k) if (nap[k])
			{
				int nl=gl[k],nr=gr[k];
				cu+=(nr-lar)*1ll*nl;
			}
			an+=cu;
			
			if (sz==1)
			{
				int c=gl[subs[i][0]];
				int cv=gl[subs[i][0]]-gl[subs[i][0]+1];
				an-=2*c;
				an-=cv;
				an+=2;
			}
		}
	}
	cout<<an<<en;
}

詳細信息

Test #1:

score: 100
Accepted
time: 19ms
memory: 58492kb

input:

4 3 300
1 10
2 25
2 30
3 50

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 19ms
memory: 58428kb

input:

4 6 200000
6 1
6 1
1 2
2 2

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: -100
Wrong Answer
time: 68ms
memory: 62704kb

input:

191580 64997 56
24878 1
35060 1
24245 1
64330 1
9650 1
15423 1
34953 1
21456 1
36718 1
21395 1
17613 1
16995 1
45257 1
31277 1
20026 1
1870 1
25581 1
9997 1
54701 1
30752 1
32269 1
705 1
64186 1
58881 1
24614 1
55311 1
18259 1
58886 1
23296 1
17628 1
3411 1
37469 1
47951 1
12188 1
60720 1
54168 1
45...

output:

285755273915142

result:

wrong answer 1st numbers differ - expected: '274533940012863', found: '285755273915142'