QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880695#9698. Twenty-twozqsWA 2ms5376kbC++145.4kb2025-02-03 17:58:102025-02-03 17:58:11

Judging History

This is the latest submission verdict.

  • [2025-02-03 17:58:11]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 5376kb
  • [2025-02-03 17:58:10]
  • Submitted

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#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 ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
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;
}

#define mod 998244353
struct modint{
	unsigned 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?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,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	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 455
#define inf 0x3f3f3f3f

int n,m,k;
int a[maxn],c1[maxn];
struct node{
	int l,r,c;
}t[maxn];

int cto[maxn];
int b[maxn];

set<vi>S;
void brute(){
//	For(i,1,k) cout<<cto[i]<<" "; cout<<"cto\n";
	For(i,1,n) b[i]=a[i];
	For(i,1,k) {
		For(j,t[i].l,t[i].r)
			b[j]=max(b[j],cto[i]);
	}
	//For(i,1,n) cout<<b[i]<<" "; cout<<" b\n";
	vi o;
	For(i,1,n) o.pb(b[i]);
	S.insert(o);
}

int tmp[maxn],len;
modint f[maxn][maxn],g[maxn][maxn];

vi buc[maxn];

int c[maxn],vis[maxn];
ull dp[maxn];

int ff[maxn];
int gf(int x){
	while(x!=ff[x])x=ff[x]=ff[ff[x]];
	return x;
}

int mns;
void del(int l,int r){
	for(int u=gf(l);u<=r;u=gf(u+1)) c[u]=1,ff[u]=u+1,mns=min(mns,u);
}

vi qs[maxn];

signed main()
{
//	freopen("data.in","r",stdin);
	n=read(),m=read(),k=read();
	For(i,1,n)a[i]=read();
	For(i,1,m)c1[i]=read();
	For(i,1,k){
		t[i].l=read(),t[i].r=read(),t[i].c=read();
		For(j,t[i].l,t[i].r) a[j]=max(a[j],t[i].c); 
	}
	sort(c1+1,c1+m+1);
	m=unique(c1+1,c1+m+1)-c1-1;
	
	For(i,1,n) a[i]=min(a[i],c1[1]);
	For(i,1,n) a[i]=max(a[i],c1[1]),assert(a[i]==c1[1]);
	// now a[i]=c1[1]!!
	
	int k2=0;
	For(i,1,k){
		if(t[i].c>c1[1]) t[++k2]=t[i];
	}k=k2;
	
	For(i,1,n) tmp[++len]=a[i];
	For(i,1,m) tmp[++len]=c1[i];
	For(i,1,k) tmp[++len]=t[i].c;
	sort(tmp+1,tmp+len+1),len=unique(tmp+1,tmp+len+1)-tmp-1;
	#define V(x) lower_bound(tmp+1,tmp+len+1,x)-tmp
	For(i,1,n) a[i]=V(a[i]);
	For(i,1,m) c1[i]=V(c1[i]);
	For(i,1,k) t[i].c=V(t[i].c);
	
	For(i,1,m) vis[c1[i]]=1;
	For(i,1,k){
		buc[t[i].c].pb(i);
		For(j,1,t[i].c-1) if(vis[j]) buc[j].pb(i);
	}
	
	For(l,1,n+1) f[l][l-1]=g[l][l-1]=1;
	Rep(i,len,1){
	//	cout<<"I: "<<tmp[i]<<"\n";
		For(l,0,n) For(r,l,n) g[l][r]=f[l][r],f[l][r]=0;
		For(l,1,n){
			
			c[l-1]=1;
			For(r,l,n+1) ff[r]=r,c[r]=0,qs[r].clear();
			for(int id:buc[i])
				if(l<=t[id].l) qs[t[id].r].pb(id);
			
			For(r,l,n){
				mns=r+1;
				for(int id:qs[r]) del(t[id].l,t[id].r);
			//	for(int id:qs[r]) 
			//		if(l<=t[id].l && t[id].r<=r) c[t[id].l]++,c[t[id].r+1]--;
			//	For(p,l+1,r+1) c[p]+=c[p-1];
			//	c[l-1]=1;
				
				c[r+1]+=1;
				For(p,mns,r+1) dp[p]=0;
				dp[l-1]=1;
				
				For(p,l-1,mns-1) if((c[p] || i==1) && dp[p]) {
					unsigned long long pp = (((unsigned __int128)dp[p] << 64) + mod - 1) / mod;
					For(q,mns,r+1) dp[q] += ((unsigned)g[p+1][q-1].x * pp * (unsigned __int128)mod >> 64);
				}
				For(p,mns,r+1) if((c[p] || i==1) && dp[p]) {
					dp[p]%=mod;
					unsigned long long pp = (((unsigned __int128)dp[p] << 64) + mod - 1) / mod;
					For(q,p+1,r+1)
						dp[q] += ((unsigned)g[p+1][q-1].x * pp * (unsigned __int128)mod >> 64);
				}
				
//				For(p,l-1,r) if((c[p] || i==1) && dp[p]) {
//					dp[p]%=mod;
//					unsigned long long pp = (((unsigned __int128)dp[p] << 64) + mod - 1) / mod;
//					For(q,p+1,r+1)
//						dp[q] += ((unsigned)g[p+1][q-1].x * pp * (unsigned __int128)mod >> 64);
//						//dp[q]%=mod;
//				}
				c[r+1]-=1;
				dp[r+1]%=mod;
				f[l][r]=dp[r+1];
			}
		}
			
//		For(l,1,n){
//			For(r,l,n){
//				cout<<f[l][r].x<<" ";
//			}cout<<"\n";
//		}
	}
	cout<<f[1][n].x;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2 2
4 1 3 5 2
2 4
1 3 3
2 5 5

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

13 2 1
12 13 4 12 9 12 11 3 13 1 3 8 10
3 9
6 7 10

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5248kb

input:

16 3 2
9 16 6 15 8 7 6 3 11 12 14 9 12 13 1 2
12 15 9
1 2 10
4 5 14

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

8 1 4
8 2 7 4 8 7 7 5
4
1 2 3
4 7 5
5 6 8
3 8 6

output:

6

result:

ok 1 number(s): "6"

Test #5:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

6 2 2
1 4 3 5 3 6
5 6
4 5 6
1 1 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

7 2 6
3 4 7 7 1 3 4
2 1
5 6 3
1 2 4
1 4 6
3 4 5
4 5 6
1 5 2

output:

76

result:

ok 1 number(s): "76"

Test #7:

score: 0
Accepted
time: 1ms
memory: 5248kb

input:

7 1 5
7 6 1 5 7 1 6
1
4 4 7
6 7 6
6 6 4
5 6 1
6 7 7

output:

8

result:

ok 1 number(s): "8"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5248kb

input:

18 3 2
5 9 12 12 6 12 9 14 8 16 12 9 12 13 6 18 4 18
13 15 1
5 5 2
6 13 18

output:

8

result:

ok 1 number(s): "8"

Test #9:

score: 0
Accepted
time: 0ms
memory: 5120kb

input:

14 2 2
4 1 9 2 6 9 7 2 2 3 12 10 14 5
2 4
6 6 8
7 10 14

output:

9

result:

ok 1 number(s): "9"

Test #10:

score: 0
Accepted
time: 1ms
memory: 4992kb

input:

20 2 2
17 4 9 9 1 16 12 1 8 14 16 12 3 5 5 3 14 15 7 6
1 15
1 13 2
4 20 1

output:

2

result:

ok 1 number(s): "2"

Test #11:

score: 0
Accepted
time: 0ms
memory: 4992kb

input:

10 2 6
9 4 3 4 10 5 9 2 3 4
7 10
4 10 10
2 7 2
6 7 9
4 10 7
9 10 2
7 8 2

output:

3

result:

ok 1 number(s): "3"

Test #12:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

6 1 5
6 4 4 2 1 2
3
2 4 3
1 3 3
1 4 5
1 1 2
4 5 5

output:

4

result:

ok 1 number(s): "4"

Test #13:

score: 0
Accepted
time: 0ms
memory: 5120kb

input:

6 3 4
2 5 3 2 3 1
1 1 4
4 5 3
2 5 6
4 5 6
2 3 1

output:

7

result:

ok 1 number(s): "7"

Test #14:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

7 3 3
2 5 1 6 4 4 4
7 3 7
4 7 6
3 7 2
2 4 5

output:

4

result:

ok 1 number(s): "4"

Test #15:

score: 0
Accepted
time: 1ms
memory: 5376kb

input:

14 3 7
13 11 9 1 9 6 9 11 11 5 1 10 10 8
4 5 2
3 7 10
13 13 8
10 11 3
1 3 1
5 7 8
9 13 2
5 8 1

output:

80

result:

ok 1 number(s): "80"

Test #16:

score: 0
Accepted
time: 1ms
memory: 5248kb

input:

18 1 7
15 12 16 6 13 7 16 2 13 8 12 15 4 5 9 15 15 16
6
9 11 8
2 14 15
6 18 5
8 10 11
4 11 7
2 5 14
8 10 7

output:

21

result:

ok 1 number(s): "21"

Test #17:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

13 1 5
8 10 11 6 12 7 5 9 9 13 12 1 7
9
5 11 2
2 12 13
6 13 10
8 13 4
2 11 3

output:

4

result:

ok 1 number(s): "4"

Test #18:

score: 0
Accepted
time: 2ms
memory: 5248kb

input:

19 1 5
3 9 7 19 14 1 13 3 1 4 4 10 2 19 13 1 1 4 17
2
13 16 9
7 9 6
4 5 12
9 10 10
3 5 18

output:

24

result:

ok 1 number(s): "24"

Test #19:

score: 0
Accepted
time: 0ms
memory: 5248kb

input:

7 2 3
5 6 4 6 2 5 1
1 1
1 5 7
3 3 5
5 5 5

output:

5

result:

ok 1 number(s): "5"

Test #20:

score: -100
Wrong Answer
time: 0ms
memory: 5248kb

input:

1 2 7
1
1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1

output:

0

result:

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