제출 #961478

#제출 시각아이디문제언어결과실행 시간메모리
961478hmm789서열 (APIO23_sequence)C++17
13 / 100
2061 ms85680 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; struct node { int s, e, m, mn, mx, lz; node *l, *r; node(int _s, int _e) { s = _s, e = _e, m = (s+e)/2, mn = mx = lz = 0; if(s != e) { l = new node(s, m); r = new node(m+1, e); } } void prop() { if(lz == 0) return; mn += lz; mx += lz; if(s != e) { l->lz += lz; r->lz += lz; } lz = 0; } void radd(int x, int y, int val) { prop(); if(x <= s && e <= y) {lz += val; return;} else if(x > m) r->radd(x, y, val); else if(y <= m) l->radd(x, y, val); else l->radd(x, y, val), r->radd(x, y, val); l->prop(); r->prop(); mn = min(l->mn, r->mn); mx = max(l->mx, r->mx); } int rmin(int x, int y) { prop(); if(x <= s && e <= y) return mn; else if(x > m) return r->rmin(x, y); else if(y <= m) return l->rmin(x, y); else return min(l->rmin(x, y), r->rmin(x, y)); } int rmax(int x, int y) { prop(); if(x <= s && e <= y) return mx; else if(x > m) return r->rmax(x, y); else if(y <= m) return l->rmax(x, y); else return max(l->rmax(x, y), r->rmax(x, y)); } } *root; int sequence(int n, std::vector<int> a) { reverse(a.begin(), a.end()); a.push_back(0); reverse(a.begin(), a.end()); int ans = 0; vector<int> pos[n+2]; for(int i = 1; i <= n; i++) pos[i].push_back(0); for(int i = 1; i <= n; i++) pos[a[i]].push_back(i); for(int i = 1; i <= n; i++) pos[i].push_back(n+1); root = new node(0, n); for(int i = 1; i <= n; i++) { if(a[i] > 1) root->radd(i, n, 1); } for(int i = 1; i <= n; i++) { // value i int l = 1, r = (int)pos[i].size()-1, m; while(l < r) { m = (l+r)/2; bool ok = false; for(int j = 1; j < pos[i].size()-m; j++) { int mn1 = root->rmin(pos[i][j-1], pos[i][j]-1); int mx1 = root->rmax(pos[i][j-1], pos[i][j]-1); int mn2 = root->rmin(pos[i][j+m-1], pos[i][j+m]-1); int mx2 = root->rmax(pos[i][j+m-1], pos[i][j+m]-1); if(mn2 < mn1) swap(mn1, mn2), swap(mx1, mx2); if(mn1+m >= mn2 && mn1+m <= mx2) { ok = true; break; } if(mx1 > mx2) swap(mn1, mn2), swap(mx1, mx2); if(mx2-m >= mn1 && mn2-m <= mx1) { ok = true; break; } } if(ok) l = m+1; else r = m; } ans = max(ans, l-1); for(int j : pos[i]) if(j != 0 && j != n+1) root->radd(j, n, -1); for(int j : pos[i+1]) if(j != 0 && j != n+1) root->radd(j, n, -1); } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:69:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for(int j = 1; j < pos[i].size()-m; j++) {
      |                            ~~^~~~~~~~~~~~~~~~~
#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...