Submission #855417

# Submission time Handle Problem Language Result Execution time Memory
855417 2023-10-01T08:32:18 Z MilosMilutinovic Sequence (APIO23_sequence) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int N=5000500;

int n,a[N],val[N],pref[N];
vector<int> pos[N];

struct info{
	ll mn_pref,mx_pref,mn_suff,mx_suff,tag;
}st[4*N];


int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),pos[a[i]].pb(i);
	//build(1,1,n);
	for(int i=1;i<=n;i++) val[i]=1;
	int ans=0;
	for(int v=1;v<=n;v++){
		if(pos[v].empty()) continue;
		for(int j:pos[v]) val[j]=0;
//		for(int j:pos[v]) modify(1,1,n,j,n,-1);
		for(int i=1;i<=n;i++) pref[i]=pref[i-1]+val[i];
		for(int l=1;l<=n;l++){
			int cnt=0;
			for(int r=l;r<=n;r++){
				cnt+=(a[r]==v?1:0);
				if(abs(pref[r]-pref[l-1])<=cnt) ans=max(ans,cnt);
			}
		}
//		for(int j:pos[v]) modify(1,1,n,j,n,-1);
		for(int j:pos[v]) val[j]=-1;
	}
	printf("%d\n",ans);
	return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
sequence.cpp:32:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  for(int i=1;i<=n;i++) scanf("%d",&a[i]),pos[a[i]].pb(i);
      |                        ~~~~~^~~~~~~~~~~~
/usr/bin/ld: /tmp/cc8AGtZC.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccF4L28C.o:sequence.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc8AGtZC.o: in function `main':
grader.cpp:(.text.startup+0x2a4): undefined reference to `sequence(int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status