제출 #650485

#제출 시각아이디문제언어결과실행 시간메모리
650485Koful123Xylophone (JOI18_xylophone)C++17
47 / 100
82 ms344 KiB
#include <bits/stdc++.h> #include <xylophone.h> using namespace std; void solve(int n){ int l = 1,r = n; vector<int> v(n+1),th(n+1),se(n+1); while(l < r){ int m = (l + r) / 2; if(query(1,m) == n-1) r = m; else l = m + 1; } v[l] = n; if(l != n){ se[l+1] = query(l,l+1); v[l+1] = n - se[l+1]; } for(int i=l+2;i<=n;i++){ se[i] = query(i-1,i),th[i] = query(i-2,i); if(th[i] == se[i-1]){ v[i] = v[i-1] + (v[i-2] > v[i-1] ? se[i] : -se[i]); } else{ if(v[i-2] > v[i-1]){ if(se[i] == th[i]) v[i] = v[i-1] + se[i]; else v[i] = v[i-1] - se[i]; } else{ if(th[i] == se[i]) v[i] = v[i-1] - se[i]; else v[i] = v[i-1] + se[i];; } } } if(l != 1){ se[l-1] = query(l-1,l); v[l-1] = n - se[l-1]; } for(int i=l-2;i>=1;i--){ se[i] = query(i,i+1),th[i] = query(i,i+2); if(th[i] == se[i+1]){ v[i] = v[i+1] + (v[i+2] > v[i+1] ? se[i] : -se[i]); } else{ if(v[i+2] > v[i+1]){ if(se[i] == th[i]) v[i] = v[i+1] + se[i]; else v[i] = v[i+1] - se[i]; } else{ if(th[i] == se[i]) v[i] = v[i+1] - se[i]; else v[i] = v[i+1] + se[i]; } } } for(int i=1;i<=n;i++){ answer(i,v[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...