Submission #751841

# Submission time Handle Problem Language Result Execution time Memory
751841 2023-06-01T15:13:16 Z 1075508020060209tc Sequence (APIO23_sequence) C++17
28 / 100
2000 ms 10316 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int lowbit(int x){return x&-x;}

struct BIT{
vector<int>bit;
int MX;
void init(int len){
for(int i=0;i<=len+100;i++){
    bit.push_back(0);
}
MX=len;
}
void upd(int pl,int vl){
while(pl<=MX){
    bit[pl]+=vl;
    pl+=lowbit(pl);
}
}
int qsum(int pl){
int ret=0;
while(pl){
    ret+=bit[pl];
    pl-=lowbit(pl);
}
return ret;
}
int k_th(int k){
int lg=__lg(MX);
int cnt=0;
int nw=0;
for(int i=lg;i>=0;i--){
    if(cnt+bit[nw+(1<<i)]<k){
        nw+=(1<<i);
        cnt+=bit[nw];
    }
}
return nw+1;
}
};


int n;
int ar[500005];
int freq[500005];

int slv(){
   int ans=0;
   BIT num;
   num.init((1<<(__lg(n)+1)));
    for(int l=1;l<=n;l++){
        for(int r=l;r<=n;r++){
            freq[ar[r]]++;
            num.upd(ar[r],1);
            int len=r-l+1;
            ans=max(ans,freq[num.k_th((len+1)/2)]);
            ans=max(ans,freq[num.k_th((len+2)/2)]);
        }
        for(int r=l;r<=n;r++){
            freq[ar[r]]--;
            num.upd(ar[r],-1);
        }
    }
    return ans;
}


int sequence(int N, std::vector<int> A) {
    n=N;
    for(int i=0;i<n;i++){
        ar[i+1]=A[i];
    }
return slv();

  return 0;
}

/*

signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>ar[i];
    }
    cout<<slv();


    return 0;
}

*/

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 196 ms 356 KB Output is correct
14 Correct 195 ms 356 KB Output is correct
15 Correct 205 ms 344 KB Output is correct
16 Correct 216 ms 352 KB Output is correct
17 Correct 202 ms 344 KB Output is correct
18 Correct 186 ms 352 KB Output is correct
19 Correct 209 ms 352 KB Output is correct
20 Correct 191 ms 352 KB Output is correct
21 Correct 194 ms 340 KB Output is correct
22 Correct 203 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 2063 ms 10304 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 2072 ms 10316 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 10304 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 196 ms 356 KB Output is correct
14 Correct 195 ms 356 KB Output is correct
15 Correct 205 ms 344 KB Output is correct
16 Correct 216 ms 352 KB Output is correct
17 Correct 202 ms 344 KB Output is correct
18 Correct 186 ms 352 KB Output is correct
19 Correct 209 ms 352 KB Output is correct
20 Correct 191 ms 352 KB Output is correct
21 Correct 194 ms 340 KB Output is correct
22 Correct 203 ms 372 KB Output is correct
23 Execution timed out 2073 ms 2380 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 196 ms 356 KB Output is correct
14 Correct 195 ms 356 KB Output is correct
15 Correct 205 ms 344 KB Output is correct
16 Correct 216 ms 352 KB Output is correct
17 Correct 202 ms 344 KB Output is correct
18 Correct 186 ms 352 KB Output is correct
19 Correct 209 ms 352 KB Output is correct
20 Correct 191 ms 352 KB Output is correct
21 Correct 194 ms 340 KB Output is correct
22 Correct 203 ms 372 KB Output is correct
23 Execution timed out 2063 ms 10304 KB Time limit exceeded
24 Halted 0 ms 0 KB -