QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718860#9610. 游戏Crysfly0 48ms6004kbC++203.2kb2024-11-06 21:37:502024-11-06 21:37:53

Judging History

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

  • [2024-11-06 21:37:53]
  • 评测
  • 测评结果:0
  • 用时:48ms
  • 内存:6004kb
  • [2024-11-06 21:37:50]
  • 提交

answer

// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
//#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}
// modint
#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 200005
#define inf 0x3f3f3f3f

int n,m,a[maxn];

pii t1[maxn],t2[maxn],tx[maxn],ty[maxn];
int len1,len2;
bool vis[maxn];

void brute()
{
	For(_,1,m){
		int x=read(),y=read();
		len1=len2=0;
		For(i,1,n){
			if(a[i]<=x)t1[++len1]=mkp(x-a[i],i);
			else t2[++len2]=mkp(a[i]-x,i);
		}
		reverse(t1+1,t1+len1+1);
		merge(t1+1,t1+len1+1,t2+1,t2+len2+1,tx+1);
		len1=len2=0;
		swap(x,y);
		For(i,1,n){
			if(a[i]<=x)t1[++len1]=mkp(x-a[i],i);
			else t2[++len2]=mkp(a[i]-x,i);
		}
		reverse(t1+1,t1+len1+1);
		merge(t1+1,t1+len1+1,t2+1,t2+len2+1,ty+1);
		swap(x,y);
		modint res=0;
		int p1=1,p2=1;
	//	For(i,1,n)cout<<tx[i].se<<" "<<tx[i].fi<<endl;puts("");
		For(i,1,n){
			if(i&1){
				while(vis[tx[p1].se])++p1;
				vis[tx[p1].se]=1,res+=a[tx[p1].se];
	//			cout<<"add "<<p1<<" "<<a[tx[p1].se]<<endl;
			}else{
				while(vis[ty[p2].se])++p2;
				vis[ty[p2].se]=1;
			}
		}
		printf("%d\n",res.x);
		For(i,1,n)vis[i]=0;
	}
}

signed main()
{
	//freopen("card.in","r",stdin);
	//freopen("card.out","w",stdout);
	n=read(),m=read();
	For(i,1,n)a[i]=read();
	if(n<=5000)brute();
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 48ms
memory: 6004kb

input:

5000 2000 0
115 126
1542 1589
1770 1774
2876 2915
3533 3539
7176 7176
7734 7767
8709 8751
9090 9116
9203 9243
10529 10550
12013 12059
13857 13891
14952 14978
15892 15904
16431 16471
16992 17037
17217 17252
18012 18025
18835 18857
19069 19098
19304 19335
19368 19395
19742 19785
21043 21088
22572 2260...

output:

111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
111281642
...

result:

wrong answer 1st lines differ - expected: '481592148304036', found: '111281642'

Subtask #2:

score: 0
Time Limit Exceeded

Test #9:

score: 0
Time Limit Exceeded

input:

5000 2000000 0
333 376
1484 1485
1602 1625
1751 1751
3230 3264
3473 3522
5932 5942
6782 6813
6830 6863
6982 7007
7013 7034
7226 7259
8555 8585
8652 8668
9354 9389
9440 9486
9942 9963
12552 12599
13153 13174
14096 14139
14895 14903
17478 17490
18195 18227
18907 18941
19183 19214
19635 19670
19984 200...

output:

102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
102621431
...

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #17:

score: 0
Time Limit Exceeded

input:

5000 2000000 1
53 53
54 54
1775 1775
1776 1776
2217 2217
2312 2312
4982 4982
5212 5212
5213 5213
5214 5214
6199 6199
8528 8528
10141 10141
10142 10142
10719 10719
10720 10720
10721 10721
11868 11868
12311 12311
12312 12312
12313 12313
16789 16789
18899 18899
18900 18900
22515 22515
22516 22516
25061...

output:

65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
65654519
656...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%