# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
407286 | drkarlicio2107 | Fountain (eJOI20_fountain) | C++14 | 89 ms | 34616 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std; int par [100010]; vector <int> ch [100010]; long long int pro [100010]; long long int kap [100010];
int LCA [100010][20]; stack < pair <long long int, int> > s; long long int inf=1e18;
long long int pref [100010];
void calc (long long int tonow, int node){
for (int i=0; i<ch[node].size(); i++) calc (tonow+kap[node], ch[node][i]);
pref[node]=tonow+kap[node];
return ;
}
int main(){
int n,q; cin >> n >> q;
for (int i=0; i<n; i++){
cin >> pro[i] >> kap [i];
}
//building tree
par [n]=-1; s.push (make_pair (inf, n)); kap [n]=inf;
for (int i=n-1; i>=0; i--){
int x;
while (s.top().first<=pro[i]) s.pop();
x=s.top().second; s.push (make_pair(pro[i], i));
par [i]=x; ch [x].push_back(i);
}
//building LCA
for (int i=0; i<n+1; i++) LCA [i][0]=par [i];
for (int j=1; j<20; j++){
for (int i=0; i<n+1; i++){
LCA [i][j]=LCA [LCA[i][j-1]][j-1];
}
}
cout << endl;
//making prefix
calc (0, n);
//answering queryes
for (int i=0; i<q; i++){
int poc; long long int val; cin >> poc >> val; poc--; int x=poc;
while (1) {
if (x==n) break;
if (pref[poc]-pref[LCA[x][0]]>=val) break;
if (par[par[x]]==-1 || pref[poc]-pref[LCA[x][1]]>=val){
x=par[x]; break;
}
for (int j=1; j<20; j++){
int now=LCA[x][j];
cout << now << endl;
if (now==-1 || par[now]==-1 || LCA[now][0]==-1){
x=n; break;
}
if (pref[poc]-pref[par[now]]>=val){
x=LCA[x][j-1]; break;
}
}
}
if (x!=n) cout << x+1 << endl;
else cout << 0 << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |