Submission #706311

# Submission time Handle Problem Language Result Execution time Memory
706311 2023-03-06T09:20:34 Z MinhAnhnd Cigle (COI21_cigle) C++14
100 / 100
423 ms 233544 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define ll unsigned long long

using namespace __gnu_pbds;

#define modu 1000003233

struct point{
    long index,outdegree;
};
//hyper_adj[a] -> b then (a before b)

bool ss(point a, point b){
    return a.outdegree>b.outdegree;
}

bool iss(point a, point b){
    return a.index>b.index;
}
ll multiply(ll a,ll b){
    return ((a%modu)*(b%modu))%modu;
}

ll sum(ll a,ll b){
    return ((a%modu)+(b%modu))%modu;
}

#define sizeofA 6001

long long  N;

//hyper_adj[a] -> b then (a before b)

const long long  Nsize = sizeofA*2;  // limit for array size
long long  n;  // array size
long long  t[2 * Nsize] = {};

void build() {  // build the tree
  //for (long long  i = n - 1; i > 0; --i) t[i] = t[i<<1] + t[i<<1|1];
  //for (long long  i = n - 1; i > 0; --i) t[i] = t[i<<1] + t[i<<1|1];
  for (long long  i = n - 1; i > 0; --i) t[i] = max(t[i<<1],t[i<<1|1]);
}

void modify(long long  p, long long  value) {  // set value at position p
  //for (t[p += n] += value; p > 1; p >>= 1) t[p>>1] = t[p] + t[p^1];
  for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = max(t[p], t[p^1]);
}

long long  query(long long  l, long long  r) {  // sum on long long erval [l, r)
  long long  res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = max(res,t[l++]) ;
    if (r&1) res = max(res,t[--r]) ;
  }
  return res;
}

int main(){
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    cin>>N;
    long temp;
    long A[sizeofA];
    long Sum[sizeofA] ={};
    int have[sizeofA*sizeofA] = {};
    cin>>A[1];
    N = N-2;
    n = N;
    for (long i = 1;i<=N;i++){
        cin>>A[i];
        Sum[i] = Sum[i-1] + A[i];
        have[Sum[i]] = i;
    }
    long i_val[sizeofA] = {};
    cin>>temp;
    vector<pair<long,long>> to_get[sizeofA];
    long ans = 0;
    vector<pair<long,long>> to_modify[sizeofA+3];

    for (long i = 1;i<=N;i++){
        for (auto k: to_modify[i]){

            long pivot = k.first;
            i_val[pivot] = max(i_val[pivot],k.second);
            modify(pivot,i_val[pivot]);
            //cout<<k.first<<" "<<k.second<<" "<<i<<endl;
        }
        long need = Sum[i]*2;
        long number_up = 0;

        for(long j = i-1;j>=0;j--){
            int delta = need - Sum[j];
            if (have[delta]>0){

                number_up++;

                //to_get[i].push_back(make_pair((long)j+1,(long)have[delta]));
                long lower_end = j+1;
                long pivot = i;
                long upper_end = have[delta];

                long current_val = query(0,lower_end-1) + number_up;
                //
                ans = max(current_val,ans);
                //cout<<lower_end<<" "<<pivot<<" "<<current_val<<" "<<upper_end<<" "<<delta<<endl;

                //cout<<lower_end<<" "<<pivot<<" "<<current_val<<" "<<upper_end<<" "<<endl;
                to_modify[upper_end+1].push_back(make_pair(pivot,current_val));

                //modify(pivot,i_val);

                /*for (long i = 1;i<=N*2;i++){
                    cout<<t[i]<<" ";

                }; cout<<endl;*/
            }
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 68 ms 141664 KB Output is correct
2 Correct 72 ms 141608 KB Output is correct
3 Correct 68 ms 141596 KB Output is correct
4 Correct 66 ms 141600 KB Output is correct
5 Correct 67 ms 141592 KB Output is correct
6 Correct 70 ms 141576 KB Output is correct
7 Correct 67 ms 141668 KB Output is correct
8 Correct 68 ms 141672 KB Output is correct
9 Correct 66 ms 141696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 141664 KB Output is correct
2 Correct 72 ms 141608 KB Output is correct
3 Correct 68 ms 141596 KB Output is correct
4 Correct 66 ms 141600 KB Output is correct
5 Correct 67 ms 141592 KB Output is correct
6 Correct 70 ms 141576 KB Output is correct
7 Correct 67 ms 141668 KB Output is correct
8 Correct 68 ms 141672 KB Output is correct
9 Correct 66 ms 141696 KB Output is correct
10 Correct 66 ms 141652 KB Output is correct
11 Correct 70 ms 141676 KB Output is correct
12 Correct 67 ms 141644 KB Output is correct
13 Correct 70 ms 141640 KB Output is correct
14 Correct 69 ms 141676 KB Output is correct
15 Correct 70 ms 141588 KB Output is correct
16 Correct 67 ms 141656 KB Output is correct
17 Correct 66 ms 141644 KB Output is correct
18 Correct 67 ms 141684 KB Output is correct
19 Correct 69 ms 141772 KB Output is correct
20 Correct 80 ms 141584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 142252 KB Output is correct
2 Correct 69 ms 142696 KB Output is correct
3 Correct 71 ms 142512 KB Output is correct
4 Correct 81 ms 142736 KB Output is correct
5 Correct 76 ms 142732 KB Output is correct
6 Correct 70 ms 142708 KB Output is correct
7 Correct 69 ms 142744 KB Output is correct
8 Correct 70 ms 142716 KB Output is correct
9 Correct 70 ms 142764 KB Output is correct
10 Correct 69 ms 142572 KB Output is correct
11 Correct 86 ms 142564 KB Output is correct
12 Correct 73 ms 142448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 141664 KB Output is correct
2 Correct 72 ms 141608 KB Output is correct
3 Correct 68 ms 141596 KB Output is correct
4 Correct 66 ms 141600 KB Output is correct
5 Correct 67 ms 141592 KB Output is correct
6 Correct 70 ms 141576 KB Output is correct
7 Correct 67 ms 141668 KB Output is correct
8 Correct 68 ms 141672 KB Output is correct
9 Correct 66 ms 141696 KB Output is correct
10 Correct 66 ms 141652 KB Output is correct
11 Correct 70 ms 141676 KB Output is correct
12 Correct 67 ms 141644 KB Output is correct
13 Correct 70 ms 141640 KB Output is correct
14 Correct 69 ms 141676 KB Output is correct
15 Correct 70 ms 141588 KB Output is correct
16 Correct 67 ms 141656 KB Output is correct
17 Correct 66 ms 141644 KB Output is correct
18 Correct 67 ms 141684 KB Output is correct
19 Correct 69 ms 141772 KB Output is correct
20 Correct 80 ms 141584 KB Output is correct
21 Correct 75 ms 142252 KB Output is correct
22 Correct 69 ms 142696 KB Output is correct
23 Correct 71 ms 142512 KB Output is correct
24 Correct 81 ms 142736 KB Output is correct
25 Correct 76 ms 142732 KB Output is correct
26 Correct 70 ms 142708 KB Output is correct
27 Correct 69 ms 142744 KB Output is correct
28 Correct 70 ms 142716 KB Output is correct
29 Correct 70 ms 142764 KB Output is correct
30 Correct 69 ms 142572 KB Output is correct
31 Correct 86 ms 142564 KB Output is correct
32 Correct 73 ms 142448 KB Output is correct
33 Correct 68 ms 142320 KB Output is correct
34 Correct 69 ms 142488 KB Output is correct
35 Correct 68 ms 142672 KB Output is correct
36 Correct 68 ms 142800 KB Output is correct
37 Correct 76 ms 142744 KB Output is correct
38 Correct 71 ms 142656 KB Output is correct
39 Correct 68 ms 141900 KB Output is correct
40 Correct 67 ms 141592 KB Output is correct
41 Correct 69 ms 141644 KB Output is correct
42 Correct 69 ms 141628 KB Output is correct
43 Correct 73 ms 141636 KB Output is correct
44 Correct 67 ms 141644 KB Output is correct
45 Correct 68 ms 141652 KB Output is correct
46 Correct 68 ms 141588 KB Output is correct
47 Correct 67 ms 141616 KB Output is correct
48 Correct 79 ms 141680 KB Output is correct
49 Correct 80 ms 141664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 141664 KB Output is correct
2 Correct 72 ms 141608 KB Output is correct
3 Correct 68 ms 141596 KB Output is correct
4 Correct 66 ms 141600 KB Output is correct
5 Correct 67 ms 141592 KB Output is correct
6 Correct 70 ms 141576 KB Output is correct
7 Correct 67 ms 141668 KB Output is correct
8 Correct 68 ms 141672 KB Output is correct
9 Correct 66 ms 141696 KB Output is correct
10 Correct 66 ms 141652 KB Output is correct
11 Correct 70 ms 141676 KB Output is correct
12 Correct 67 ms 141644 KB Output is correct
13 Correct 70 ms 141640 KB Output is correct
14 Correct 69 ms 141676 KB Output is correct
15 Correct 70 ms 141588 KB Output is correct
16 Correct 67 ms 141656 KB Output is correct
17 Correct 66 ms 141644 KB Output is correct
18 Correct 67 ms 141684 KB Output is correct
19 Correct 69 ms 141772 KB Output is correct
20 Correct 80 ms 141584 KB Output is correct
21 Correct 75 ms 142252 KB Output is correct
22 Correct 69 ms 142696 KB Output is correct
23 Correct 71 ms 142512 KB Output is correct
24 Correct 81 ms 142736 KB Output is correct
25 Correct 76 ms 142732 KB Output is correct
26 Correct 70 ms 142708 KB Output is correct
27 Correct 69 ms 142744 KB Output is correct
28 Correct 70 ms 142716 KB Output is correct
29 Correct 70 ms 142764 KB Output is correct
30 Correct 69 ms 142572 KB Output is correct
31 Correct 86 ms 142564 KB Output is correct
32 Correct 73 ms 142448 KB Output is correct
33 Correct 68 ms 142320 KB Output is correct
34 Correct 69 ms 142488 KB Output is correct
35 Correct 68 ms 142672 KB Output is correct
36 Correct 68 ms 142800 KB Output is correct
37 Correct 76 ms 142744 KB Output is correct
38 Correct 71 ms 142656 KB Output is correct
39 Correct 68 ms 141900 KB Output is correct
40 Correct 67 ms 141592 KB Output is correct
41 Correct 69 ms 141644 KB Output is correct
42 Correct 69 ms 141628 KB Output is correct
43 Correct 73 ms 141636 KB Output is correct
44 Correct 67 ms 141644 KB Output is correct
45 Correct 68 ms 141652 KB Output is correct
46 Correct 68 ms 141588 KB Output is correct
47 Correct 67 ms 141616 KB Output is correct
48 Correct 79 ms 141680 KB Output is correct
49 Correct 80 ms 141664 KB Output is correct
50 Correct 352 ms 228068 KB Output is correct
51 Correct 345 ms 229004 KB Output is correct
52 Correct 346 ms 231496 KB Output is correct
53 Correct 394 ms 231400 KB Output is correct
54 Correct 364 ms 230484 KB Output is correct
55 Correct 371 ms 231208 KB Output is correct
56 Correct 410 ms 233544 KB Output is correct
57 Correct 423 ms 233352 KB Output is correct
58 Correct 189 ms 168952 KB Output is correct
59 Correct 107 ms 148112 KB Output is correct
60 Correct 172 ms 141732 KB Output is correct
61 Correct 150 ms 142112 KB Output is correct
62 Correct 159 ms 142052 KB Output is correct
63 Correct 111 ms 143040 KB Output is correct
64 Correct 98 ms 142620 KB Output is correct
65 Correct 100 ms 142664 KB Output is correct
66 Correct 107 ms 142460 KB Output is correct
67 Correct 126 ms 142868 KB Output is correct
68 Correct 130 ms 142664 KB Output is correct
69 Correct 147 ms 143136 KB Output is correct
70 Correct 129 ms 142084 KB Output is correct
71 Correct 129 ms 142040 KB Output is correct
72 Correct 97 ms 143020 KB Output is correct