# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72183 | 2018-08-26T05:49:22 Z | 내일_개학이다_ㅠㅠ(#2230, mAng0) | Easy Data Structure Problem (FXCUP3_easy) | C++17 | 7 ms | 1892 KB |
#include<bits/stdc++.h> using namespace std; #define pp 131072 int tree[pp+pp]; int hi[100005]; int val[100005]; vector<int> v; int dp[2][20]; int jr[131072]; int main(){ int n, m; scanf("%d%d", &n, &m); for(int i=1;i<pp+pp;i++){ tree[i] = -1; } jr[0] = 0; for(int i=1;i<pp;i++){ jr[i] = jr[i/2] + 1; } for(int i=pp;i<pp+n;i++){ scanf("%d", &tree[i]); hi[tree[i]] = i-pp; } for(int i=0;i<n;i++) val[i] = 0; for(int i=pp-1;i>=1;i--){ tree[i] = min(tree[i*2], tree[i*2+1]); if(tree[i] > 0) val[hi[tree[i]]]++; } for(int i=0;i<m;i++){ int l; scanf("%d", &l); v.clear(); for(int j=0;j<l;j++){ int su; scanf("%d", &su); v.push_back(hi[su]); } if(l == 1){ printf("%d %d\n", v[0] + 1, v[0] + 1); }else{ sort(v.begin(), v.end()); bool found = false; for(int j=0;j<=val[v[0]];j++){ int pl = v[0]; if(j) pl = pl & (~(1 << (j-1))); if(v[0] & (1 << j)){ int now = (v[0] | ((1 << j) - 1)) + 1; int lim = j; int dd = 0; bool valid = false; for(int ii=1;ii<l;ii++){ if(ii == l-1){ int nxt = jr[v[ii]-now]; if(lim == nxt) break; if(dd == 0 || (dd == 1 && lim > nxt)){ now += (1 << nxt); printf("%d %d\n", pl+1, now); valid = true; break; } }else{ int nxt0 = jr[v[ii]-now]; int nxt = jr[v[ii+1]-now]-1; int nxt2 = jr[(now & (-now))] - 1; nxt = min(nxt, nxt2); if(val[v[ii]] >= nxt && nxt0 <= nxt){ if(lim == nxt) break; if(dd == 0){ if(lim < nxt){ lim = nxt; now += (1 << lim); }else{ dd = 1; lim = nxt; now += (1 << lim); } }else{ if(lim > nxt){ lim = nxt; now += (1 << lim); }else break; } }else break; } } if(valid){ found = true; break; } }else{ int now = (v[0] | ((1 << j) - 1)) + 1; if(now > v[1]) continue; int lim = j; bool valid = false; for(int ii=1;ii<l;ii++){ if(ii == l-1){ int nxt = jr[v[ii] - now]; if(val[v[ii]] >= nxt && lim > nxt){ now += (1 << nxt); valid = true; printf("%d %d\n", pl+1, now); break; }else{ break; } }else{ int nxt0 = jr[v[ii] - now]; int nxt = jr[v[ii+1]-now]-1; if(nxt0 <= nxt && lim > nxt && val[v[ii]] >= nxt){ lim = nxt; now += (1 << lim); }else{ break; } } } if(valid){ found = true; break; } } } if(!found){ printf("-1\n"); } } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1784 KB | Correct |
2 | Incorrect | 7 ms | 1892 KB | Wrong |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1784 KB | Correct |
2 | Incorrect | 7 ms | 1892 KB | Wrong |
3 | Halted | 0 ms | 0 KB | - |