제출 #1084249

#제출 시각아이디문제언어결과실행 시간메모리
1084249hahahahaRailway Trip 2 (JOI22_ho_t4)C++17
100 / 100
209 ms219604 KiB
#include<bits/stdc++.h> using namespace std; const int K = 17; const int nx = 1e5; int spx[K][K][nx+1], spm[K][K][nx+1]; int d[nx+1]; int qux(int l, int r, int k){ int dif = 31-__builtin_clz(r-l+1); return max(spx[k][dif][l], spx[k][dif][r-(1<<dif)+1]); } int qum(int l, int r, int k){ int dif = 31-__builtin_clz(r-l+1); return min(spm[k][dif][l], spm[k][dif][r-(1<<dif)+1]); } void solve(){ int n, k, m;cin >> n >> k >> m; int lr[n+1] = {0}, rl[n+1]; int L[n+1], R[n+1]; fill(rl, rl+n+1, n+1); while(m--){ int a, b;cin >> a >> b; if(a < b) lr[a] = max(lr[a], b); else rl[a] = min(rl[a], b); } multiset<int> ms; for(int i = 1;i <= n;i++){ ms.insert(lr[i]); if(i>k) ms.erase(ms.find(lr[i-k])); R[i] = max(*ms.rbegin(), i); spx[0][0][i] = R[i]; } ms.clear(); for(int i = n;i;i--){ ms.insert(rl[i]); if(i+k<=n) ms.erase(ms.find(rl[i+k])); L[i] = min(*ms.begin(), i); spm[0][0][i] = L[i]; } for(int v = 1;v < K;v++){ for(int i = 1;i+(1<<v)-1 <= n;i++){ spx[0][v][i] = max(spx[0][v-1][i], spx[0][v-1][i+(1<<v-1)]); spm[0][v][i] = min(spm[0][v-1][i], spm[0][v-1][i+(1<<v-1)]); } } for(int V = 1;V < K;V++){ for(int i = 1;i <= n;i++){ spx[V][0][i] = qux(spm[V-1][0][i], spx[V-1][0][i], V-1); spm[V][0][i] = qum(spm[V-1][0][i], spx[V-1][0][i], V-1); } for(int v = 1;v < K;v++){ for(int i = 1;i+(1<<v)-1 <= n;i++){ spx[V][v][i] = max(spx[V][v-1][i], spx[V][v-1][i+(1<<v-1)]); spm[V][v][i] = min(spm[V][v-1][i], spm[V][v-1][i+(1<<v-1)]); } } } int q;cin >> q; while(q--){ int s, t;cin >> s >> t; int ans = 0; int Ls = s, Rs = s; for(int i = K-1;i >= 0;i--){ if(qum(Ls, Rs, i) > t || qux(Ls, Rs, i) < t){ ans |= 1<<i; int ols = Ls; Ls = qum(Ls, Rs, i); Rs = qux(ols, Rs, i); } } if(qum(Ls, Rs, 0) <= t && qux(Ls, Rs, 0) >= t) cout << ans+1 << '\n'; else cout << "-1\n"; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); solve(); }

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

Main.cpp: In function 'void solve()':
Main.cpp:41:58: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   41 |    spx[0][v][i] = max(spx[0][v-1][i], spx[0][v-1][i+(1<<v-1)]);
      |                                                         ~^~
Main.cpp:42:58: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   42 |    spm[0][v][i] = min(spm[0][v-1][i], spm[0][v-1][i+(1<<v-1)]);
      |                                                         ~^~
Main.cpp:52:59: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   52 |     spx[V][v][i] = max(spx[V][v-1][i], spx[V][v-1][i+(1<<v-1)]);
      |                                                          ~^~
Main.cpp:53:59: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   53 |     spm[V][v][i] = min(spm[V][v-1][i], spm[V][v-1][i+(1<<v-1)]);
      |                                                          ~^~
#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...