제출 #255702

#제출 시각아이디문제언어결과실행 시간메모리
255702NamnamseoRope (JOI17_rope)C++17
80 / 100
2592 ms81912 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pp; void read(int& x){ scanf("%d",&x); } template<typename T,typename... Args> void read(T& a,Args&... b){ read(a); read(b...); } #define all(x) (x).begin(),(x).end() #define pb push_back int n, m; int col[1000010]; int ans[1000010]; vector<int> adj[1000010]; int self[1000010]; const int M=1048576; int t[M<<1]; void upd(int p, int v){ p+=M; t[p]+=v; p>>=1; while(p) t[p]=max(t[p*2], t[p*2+1]), p>>=1; } int rM(int l, int r){ int ret=0; l+=M; r+=M; while(l<=r){ if(l&1) ret=max(ret, t[l++]); if((r&1)==0) ret=max(ret, t[r--]); l>>=1; r>>=1; } return ret; } void Do(){ for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t)); for(int i=1; i<=n; i+=2){ if(i+1 <= n){ int a=col[i], b=col[i+1]; if(a == b){ ++self[a]; upd(a, 2); continue; } adj[a].pb(b); adj[b].pb(a); upd(a, 1); upd(b, 1); } else upd(col[i], 1); } for(int i=1; i<=m; ++i){ for(int x:adj[i]) upd(x, -1); int jib=rM(i, i); upd(i, -jib); ans[i]=min(ans[i], n-rM(1, m)-jib ); for(int x:adj[i]) upd(x, 1); upd(i, jib); } } void Do2(){ for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t)); upd(col[1], 1); for(int i=2; i<=n; i+=2){ if(i+1 <= n){ int a=col[i], b=col[i+1]; if(a == b){ ++self[a]; upd(a, 2); continue; } adj[a].pb(b); adj[b].pb(a); upd(a, 1); upd(b, 1); } else upd(col[i], 1); } for(int i=1; i<=m; ++i){ for(int x:adj[i]) upd(x, -1); int jib=rM(i, i); upd(i, -jib); ans[i]=min(ans[i], n-rM(1, m)-jib ); for(int x:adj[i]) upd(x, 1); upd(i, jib); } } int main() { read(n, m); for(int i=1; i<=n; ++i) read(col[i]); fill(ans+1, ans+m+1, n+1); Do(); Do2(); reverse(col+1, col+n+1); Do(); Do2(); for(int i=1; i<=m; ++i) printf("%d\n", ans[i]); return 0; }

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

rope.cpp: In function 'void Do()':
rope.cpp:39:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
  ^~~
rope.cpp:39:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
                              ^~~~~~
rope.cpp: In function 'void Do2()':
rope.cpp:66:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
  ^~~
rope.cpp:66:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(auto& v:adj) v.clear(); memset(self, 0, sizeof(self)); memset(t, 0, sizeof(t));
                              ^~~~~~
rope.cpp: In function 'void read(int&)':
rope.cpp:5:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                    ~~~~~^~~~~~~~~
#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...