제출 #981960

#제출 시각아이디문제언어결과실행 시간메모리
981960nnin서열 (APIO23_sequence)C++17
31 / 100
621 ms74580 KiB
#include "sequence.h" #include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define f first #define s second vector<int> ct[500005]; int N; struct segTree { pii seg[4*500005]; int lazy[4*500005]; void laze(int i, int l, int r) { seg[i] = {seg[i].f+lazy[i], seg[i].s+lazy[i]}; if(l!=r) { lazy[i*2+1] += lazy[i]; lazy[i*2+2] += lazy[i]; } lazy[i] = 0; } void build(int i, int l, int r) { lazy[i] = 0; if(l==r) { seg[i].f = seg[i].s = l; return; } int m = (l+r)/2; build(i*2+1, l, m); build(i*2+2, m+1, r); seg[i].f = min(seg[i*2+1].f, seg[i*2+2].f); seg[i].s = max(seg[i*2+1].s, seg[i*2+2].s); } void build() { build(0, 0, N); } void update(int i, int l, int r, int wl, int wr, int val) { if(wl<=l && wr>=r) lazy[i] += val; laze(i, l, r); if(wl>r || wr<l || (wl<=l && wr>=r)) return; int m = (l+r)/2; update(i*2+1, l, m, wl, wr, val); update(i*2+2, m+1, r, wl, wr, val); seg[i].f = min(seg[i*2+1].f, seg[i*2+2].f); seg[i].s = max(seg[i*2+1].s, seg[i*2+2].s); } void update(int wl, int wr, int val) { update(0, 0, N, wl, wr, val); } pii query(int i, int l, int r, int wl, int wr) { laze(i, l, r); if(wl>r || wr<l) return {(int)1e9, (int)-1e9}; if(wl<=l && wr>=r) return seg[i]; int m = (l+r)/2; pii q1 = query(i*2+1, l, m, wl, wr); pii q2 = query(i*2+2, m+1, r, wl, wr); return {min(q1.f, q2.f), max(q1.s, q2.s)}; } pii query(int wl, int wr) { return query(0, 0, N, wl, wr); } } les, mor; int sequence(int n, std::vector<int> A) { N = n; for(int i=0;i<N;i++) { ct[A[i]].push_back(i+1); } les.build(); mor.build(); int ans = 1; for(int i=1;i<=N;i++) { for(int j:ct[i]) { les.update(j, N, -2); } for(int j=0;j+ans<ct[i].size();j++) { while(j+ans<ct[i].size()) { int st = ct[i][j]; int en = ct[i][j+ans]; int qles = les.query(en, N).f - les.query(0, st-1).s; int qmor = mor.query(en, N).s - les.query(0, st-1).f; if(qles<=0 && qmor>=0) ans++; else break; } } for(int j:ct[i]) { mor.update(j, N, -2); } } return ans; }

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

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:80:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int j=0;j+ans<ct[i].size();j++) {
      |                 ~~~~~^~~~~~~~~~~~~
sequence.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |       while(j+ans<ct[i].size()) {
      |             ~~~~~^~~~~~~~~~~~~
#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...