Submission #974463

#TimeUsernameProblemLanguageResultExecution timeMemory
974463yusuf12360Sequence (APIO23_sequence)C++17
Compilation error
0 ms0 KiB
#include "sequence.h" #include<bits/stdc++.h> using namespace std; const int N=5e5+5, INF=1e9; int n; struct node{ int mn, mx; node(int mn=0, int mx=0) : mn(mn), mx(mx) {} }; node pull(node L, node R) { int MN, MX; MN=min(L.mn, R.mn); MX=max(L.mx, R.mx); return node(MN, MX); } struct ST{ node tr[4*N]; int lazy[4*N]; node build(int pos=0, int l=0, int r=n) { lazy[pos]=0; if(l==r) return node(l, r); int mid=l+r>>1; return tr[pos]=pull(build(2*pos+1, l, mid), build(2*pos+2, mid+1, r)); } void change(int pos, int add) { tr[pos].mn+=add; tr[pos].mx+=add; lazy[pos]+=add; } void push(int pos) { change(2*pos+1, lazy[pos]); change(2*pos+2, lazy[pos]); lazy[pos]=0; } void update(int ll, int rr, int add, int pos=0, int l=0, int r=n) { if(ll>rr) return; if(ll==l && rr==r) {change(pos, add); return;} push(pos); int mid=l+r>>1; update(ll, min(rr, mid), add, 2*pos+1, l, mid); update(max(mid+1, ll), rr, add, 2*pos+2, mid+1, r); tr[pos]=pull(tr[2*pos+1], tr[2*pos+2]); } node get(int ll, int rr, int pos=0, int l=0, int r=n) { if(ll>rr) return node(INF, -INF); if(ll==l && rr==r) return tr[pos]; push(pos);int mid=l+r>>1; return pull(get(ll, min(rr, mid), 2*pos+1, l, mid), get(max(mid+1, ll), rr, 2*pos+2, mid+1, r)); } }; int sequence(int N, vector<int> a) { n=N; vector<vector<int>> pos(n+1); ST neg, pos; neg.build(); pos.build(); for(int i=0; i<n; i++) pos[a[i]].push_back(i+1); int ans=1; for(int val=1; val<=n; val++) { int SZ=pos[val].size(); for(int p : pos[val]) neg.update(p, n-1, -2); for(int p : pos[val-1]) pos.update(p, n-1, -2); for(int i=0; i<SZ; i++) { while(i+ans<SZ) { int L=pos[val][i], R=pos[val][i+ans]; int mini=neg.get(R, n).mn-neg.get(0, L-1).mx; int maxi=pos.get(R, n).mx-pos.get(0, L-1).mn; if(mini<=0 && maxi>=0) ans++; } } } return ans; }

Compilation message (stderr)

sequence.cpp: In member function 'node ST::build(int, int, int)':
sequence.cpp:23:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         int mid=l+r>>1;
      |                 ~^~
sequence.cpp: In member function 'void ST::update(int, int, int, int, int, int)':
sequence.cpp:39:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |         push(pos); int mid=l+r>>1;
      |                            ~^~
sequence.cpp: In member function 'node ST::get(int, int, int, int, int)':
sequence.cpp:47:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         push(pos);int mid=l+r>>1;
      |                           ~^~
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:55:13: error: conflicting declaration 'ST pos'
   55 |     ST neg, pos;
      |             ^~~
sequence.cpp:54:25: note: previous declaration as 'std::vector<std::vector<int> > pos'
   54 |     vector<vector<int>> pos(n+1);
      |                         ^~~
sequence.cpp:57:9: error: 'class std::vector<std::vector<int> >' has no member named 'build'
   57 |     pos.build();
      |         ^~~~~
sequence.cpp:63:37: error: 'class std::vector<std::vector<int> >' has no member named 'update'
   63 |         for(int p : pos[val-1]) pos.update(p, n-1, -2);
      |                                     ^~~~~~
sequence.cpp:70:30: error: 'class std::vector<std::vector<int> >' has no member named 'get'
   70 |                 int maxi=pos.get(R, n).mx-pos.get(0, L-1).mn;
      |                              ^~~
sequence.cpp:70:47: error: 'class std::vector<std::vector<int> >' has no member named 'get'
   70 |                 int maxi=pos.get(R, n).mx-pos.get(0, L-1).mn;
      |                                               ^~~