QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265865#7685. Barkley IIfishfishfriedfish#WA 29ms55704kbC++142.2kb2023-11-25 21:56:222023-11-25 21:56:23

Judging History

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

  • [2023-11-25 21:56:23]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:55704kb
  • [2023-11-25 21:56:22]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
//#define mp make_pair
//#define OO(x) fixed<<setprecision(x)
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=1e6+10;

struct fwt{
	int t[M],n;
	#define lowbit(x) (x&-x)
	void init(int _n){
		n=_n;
		F(i,0,n) t[i]=0;
	}
	void add(int x,int y){
		for (;x<=n;x+=lowbit(x)) t[x]+=y;
	}
	int qry(int x){
	    int ret=0;
	    for (;x;x^=lowbit(x)) ret+=t[x];
	    return ret;
	}
	
	inline int kth(int k){
	    int pos=0;
	    int cur=0;
	    DF(i,18,0){//attention!!!!
			pos^=(1<<i);
			if (pos>n || k<=t[pos]) pos^=(1<<i);
			else k-=t[pos];
		}
	    return pos+1;
	}
}A;



int n,m;
int a[M],cur[M];
struct node{
	int l,r,d;
};
vector<int> v[M];
vector<node> t[M];
bool tag[M];
void work(){
	n=read(); m=read();
	F(i,1,n) t[i].clear();
	F(i,1,n){
		a[i]=read();
		v[a[i]].pb(i);
	}
	F(i,1,n){
		if (!tag[a[i]]){
			v[a[i]].pb(n+1);
			int la=0; 
			for (int x:v[a[i]]){
	//			if (!x) continue;
				t[x-1].pb((node){la+1,x-1,a[i]});
				la=x;			
			}
			tag[a[i]]=1;
		}
	
	}
	A.init(n);
	
	int ans=-1e9;int o=0;
	F(i,1,n){
		if (cur[a[i]]) A.add(cur[a[i]],-1);
		else o++;
		cur[a[i]]=i;
		A.add(i,1);
		for (auto O:t[i]){
			if (O.l<=O.r){
//				cerr<<O.l<<" "<<O.r<<" "<<A.qry(i)-A.qry(O.l-1)<<" "<<O.d<<" interval !!\n";
				ans=max(ans,A.qry(i)-A.qry(O.l-1)-O.d);
			}
		}
	}
	
	ans=max(ans,o-m-1);
	cout<<ans<<"\n";	
	F(i,1,n) cur[a[i]]=0;
	F(i,1,n) v[a[i]].clear(),tag[a[i]]=0;

}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int T=read();
	while (T--) work(); return 0;
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 55684kb

input:

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

output:

2
3

result:

ok 2 number(s): "2 3"

Test #2:

score: -100
Wrong Answer
time: 29ms
memory: 55704kb

input:

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

output:

3
1
2
4
2
3
3
3
3
3
4
5
2
3
-1
3
1
3
7
6
3
3
-1
2
4
4
6
2
3
0
6
1
2
2
2
5
3
3
3
3
2
5
2
1
3
3
2
3
1
4
2
2
4
4
2
2
5
3
2
1
4
3
3
3
2
3
0
4
7
6
2
2
4
3
3
4
-2
6
3
3
3
3
4
0
1
1
4
5
4
5
3
1
1
2
1
3
3
4
4
3
4
2
1
3
4
4
3
-1
3
4
3
5
4
4
2
4
6
4
4
5
3
4
5
1
4
3
3
3
3
-2
3
2
1
2
5
1
2
1
4
4
2
2
4
5
4
3
-4
...

result:

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