QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468714#8904. Рекорды и антирекордыKevin090228🍬0 19ms18016kbC++233.3kb2024-07-08 23:26:522024-07-08 23:26:52

Judging History

This is the latest submission verdict.

  • [2024-07-08 23:26:52]
  • Judged
  • Verdict: 0
  • Time: 19ms
  • Memory: 18016kb
  • [2024-07-08 23:26:52]
  • Submitted

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353;
int n;
int a[200200];
namespace seg
{
	#define ls (x<<1)
	#define rs (ls|1)
	int val[200200<<2];
	ll ways[200200<<2];
	void build(int x,int l,int r)
	{
		val[x]=0;
		ways[x]=0;
		if(l==r) return ;
		int mid=(l+r)/2;
		build(ls,l,mid);
		build(rs,mid+1,r);
	}
	void modify(int x,int l,int r,int p,int v,ll w)
	{
		if(l==r)
		{
			val[x]=v;
			ways[x]=w;
			return ;
		}
		int mid=(l+r)/2;
		if(p<=mid)
			modify(ls,l,mid,p,v,w);
		else
			modify(rs,mid+1,r,p,v,w);
		val[x]=max(val[ls],val[rs]);
		ways[x]=0;
		if(val[ls]==val[x])
			ways[x]+=ways[ls];
		if(val[rs]==val[x])
			ways[x]+=ways[rs];
		ways[x]%=mod;
	}
	pair<int,ll> query(int x,int l,int r,int ql,int qr)
	{
		if(l==ql&&r==qr)
			return mp(val[x],ways[x]);
		int mid=(l+r)/2;
		if(qr<=mid)
			return query(ls,l,mid,ql,qr);
		if(ql>mid)
			return query(rs,mid+1,r,ql,qr);
		auto p1=query(ls,l,mid,ql,mid),p2=query(rs,mid+1,r,mid+1,qr);
		pair<int,ll> ret;
		ret.first=max(p1.first,p2.first);
		if(ret.first==p1.first)
			ret.second+=p1.second;
		if(ret.first==p2.first)
			ret.second+=p2.second;
		ret.second%=mod;
		return ret;
	}
	#undef ls
	#undef rs
}
int f1[200200],f2[200200],f3[200200],f4[200200];
ll g1[200200],g2[200200],g3[200200],g4[200200];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		seg::build(1,1,n);
		seg::modify(1,1,n,1,0,1);
		for(int i=1;i<=n;i++)
		{
			auto pr=seg::query(1,1,n,1,a[i]);
			f1[i]=pr.first+1;
			g1[i]=pr.second;
			seg::modify(1,1,n,a[i],f1[i],g1[i]);
		}
		seg::build(1,1,n);
		seg::modify(1,1,n,n,0,1);
		for(int i=1;i<=n;i++)
		{
			auto pr=seg::query(1,1,n,a[i],n);
			f2[i]=pr.first+1;
			g2[i]=pr.second;
			seg::modify(1,1,n,a[i],f2[i],g2[i]);
		}
		seg::build(1,1,n);
		seg::modify(1,1,n,1,0,1);
		for(int i=n;i>=1;i--)
		{
			auto pr=seg::query(1,1,n,1,a[i]);
			f3[i]=pr.first+1;
			g3[i]=pr.second;
			seg::modify(1,1,n,a[i],f3[i],g3[i]);
		}
		seg::build(1,1,n);
		seg::modify(1,1,n,n,0,1);
		for(int i=n;i>=1;i--)
		{
			auto pr=seg::query(1,1,n,a[i],n);
			f4[i]=pr.first+1;
			g4[i]=pr.second;
			seg::modify(1,1,n,a[i],f4[i],g4[i]);
		}
		int v1=*max_element(f1+1,f1+n+1);
		int v2=*max_element(f2+1,f2+n+1);
		ll w1=0,w2=0;
		for(int i=1;i<=n;i++)
			if(f1[i]==v1)
				w1=(w1+g1[i])%mod;
		for(int i=1;i<=n;i++)
			if(f2[i]==v2)
				w2=(w2+g2[i])%mod;
		ll tot=w1*w2%mod;
		for(int i=1;i<=n;i++)
			if(f1[i]+f2[i]+f3[i]+f4[i]==v1+v2+2)
				tot=(tot+mod-g1[i]*g2[i]%mod*g3[i]%mod*g4[i]%mod)%mod;
		if(!tot)
			v1--;
		cout<<v1+v2<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 21
Accepted
time: 0ms
memory: 18016kb

input:

120
5
3 1 4 2 5
5
3 4 2 5 1
5
5 4 2 1 3
5
1 2 5 4 3
5
2 4 3 1 5
5
3 1 5 2 4
5
1 4 2 3 5
5
5 1 4 3 2
5
1 5 3 2 4
5
3 1 2 5 4
5
3 1 5 4 2
5
1 2 3 4 5
5
1 5 2 4 3
5
3 5 2 1 4
5
2 1 5 4 3
5
1 5 3 4 2
5
3 1 4 5 2
5
2 1 4 5 3
5
1 3 5 4 2
5
5 3 4 2 1
5
2 1 3 5 4
5
2 3 1 5 4
5
2 4 3 5 1
5
4 3 2 5 1
5
4 5 2 ...

output:

5
5
5
5
5
4
5
5
5
4
4
5
5
5
4
5
5
4
5
5
4
4
5
5
4
5
4
5
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
4
5
5
4
5
5
5
4
5
5
5
5
4
5
5
5
5
5
5
4
5
5
5
5
5
5
4
5
4
5
5
5
5
4
5
5
4
5
4
5
4
5
5
4
4
4
4
5
5
4
4
5
5
5
4
5
4
5
5
5
4
5
4
5
5
4
4
5
5
5
4
5
5
5
5

result:

ok 120 numbers

Test #2:

score: -21
Wrong Answer
time: 0ms
memory: 15972kb

input:

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

output:

10
10
12
10
11
10
11
12
11
11
9
10
10
10
13
11
12
11
10
12
10
9
11
10
10
11
11
11
10
11
10
10
11
13
11
12
12
10
13
11
11
11
11
10
10
12
11
11
11
10
10
11
10
11
11
13
12
10
11
12
11
10
9
10
12
10
12
11
11
10
11
11
10
12
11
9
11
11
11
12
11
10
12
11
10
11
12
10
10
12
13
10
9
12
11
11
12
11
11
13
11
10...

result:

wrong answer 4th numbers differ - expected: '9', found: '10'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #49:

score: 0
Wrong Answer
time: 19ms
memory: 13972kb

input:

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

output:

8
12
13
12
9
11
14
14
9
7
12
15
6
13
8
9
8
11
10
5
7
9
11
12
8
6
14
6
6
10
6
9
8
13
6
14
13
5
6
5
9
13
6
12
14
8
4
13
12
8
9
9
11
9
13
6
6
5
11
11
11
6
5
14
13
14
12
6
14
8
8
9
7
9
15
10
7
14
8
11
5
6
8
12
9
8
12
8
9
10
8
6
10
11
10
15
12
11
12
7
8
7
9
7
13
6
12
5
7
9
10
8
13
6
7
8
13
12
10
5
9
10
7...

result:

wrong answer 4845th numbers differ - expected: '7', found: '8'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%