제출 #974694

#제출 시각아이디문제언어결과실행 시간메모리
974694yusuf12360서열 (APIO23_sequence)C++17
100 / 100
610 ms76116 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 tr[pos]=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)); } } nega, posi; int sequence(int N, vector<int> a) { n=N; vector<vector<int>> pos(n+1); nega.build(); posi.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]) nega.update(p, n, -2); for(int p : pos[val-1]) posi.update(p, n, -2); for(int i=0; i<SZ; i++) { while(i+ans<SZ) { int L=pos[val][i], R=pos[val][i+ans]; int mini=nega.get(R, n).mn-nega.get(0, L-1).mx; int maxi=posi.get(R, n).mx-posi.get(0, L-1).mn; if(mini<=0 && maxi>=0) ans++; else break; } } } return ans; }

컴파일 시 표준 에러 (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;
      |                           ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...