제출 #838789

#제출 시각아이디문제언어결과실행 시간메모리
838789VMaksimoski008Fountain (eJOI20_fountain)C++14
30 / 100
1555 ms42100 KiB
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define uniq(x) x.erase(unique(all(x)), x.end()) #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; const double eps = 1e-9; void setIO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } vector<vector<int> > up, graph; vector<vector<ll> > sum; vector<pii> v; void dfs(int u, int p) { for(int i=1; i<LOG; i++) { up[u][i] = up[ up[u][i-1] ][i-1]; sum[u][i] = 1ll * (sum[u][i-1] + sum[ up[u][i-1] ][i-1]); } for(int &next : graph[u]) { if(next == p) continue; up[next][0] = u; sum[next][0] = v[u].second + v[next].second; dfs(next, u); } } int jmp(int a, int b) { int currNode = a; int currLeft = b; while(v[currNode].second < b) { b -= v[currNode].second; currNode = up[currNode][0]; } return currNode; } int32_t main() { setIO(); int n, q; cin >> n >> q; graph.resize(n+1); up.resize(n+1, vector<int>(LOG, 0)); sum.resize(n+1, vector<ll>(LOG, 0)); v.resize(n+1); v[0] = {1500000000, 1500000000}; for(int i=1; i<=n; i++) { cin >> v[i].first >> v[i].second; } stack<pii> curr; for(int i=1; i<=n; i++) { while(!curr.empty() && curr.top().second < v[i].first) { graph[i].push_back(curr.top().first); graph[curr.top().first].push_back(i); curr.pop(); } curr.push({ i, v[i].first }); } while(!curr.empty()) { graph[0].push_back(curr.top().first); graph[curr.top().first].push_back(0); curr.pop(); } dfs(0, 0); while(q--) { int a, b; cin >> a >> b; if(v[a].second >= b) { cout << a << '\n'; continue; } cout << jmp(a, b) << '\n'; } return 0; }

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

fountain.cpp: In function 'int jmp(int, int)':
fountain.cpp:50:9: warning: unused variable 'currLeft' [-Wunused-variable]
   50 |     int currLeft = b;
      |         ^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...