이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N;
int l[200100],r[200100];
queue<pair<int,int>> q;
int d0[200100];
int dn[200100];
int Q;
struct node{
int s,e,m;
vector<int> v;
node *l,*r;
node(int S, int E){
s = S;
e = E;
m = (s + e)/2;
v = {};
if(s != e){
l = new node(s,m);
r = new node(m + 1, e);
}
}
void update(int S, int E, int k){
if(S <= s && e <= E){
v.push_back(k);
return;
}
if(S <= m){
l -> update(S,E,k);
}
if(m < E){
r -> update(S,E,k);
}
}
void pop(int i, int k){
while(!v.empty()){
q.push({v.back(),k});
v.pop_back();
}
if(s == e) return;
if(i <= m) l -> pop(i,k);
else r -> pop(i,k);
}
}*root;
int main(){
scanf(" %d",&N);
root = new node(0,N-1);
for(int i = 0; i < N; i++){
scanf(" %d",&l[i]);
scanf(" %d",&r[i]);
l[i]--;
r[i]--;
}
for(int i = 0; i < N; i++){
root -> update(l[i],r[i],i);
d0[i] = -1;
}
root -> pop(0,1);
while(!q.empty()){
pair<int,int> ii = q.front();
q.pop();
int i = ii.first;
if(d0[i] != -1) continue;
d0[i] = ii.second;
root -> pop(i,ii.second + 1);
}
root = new node(0,N-1);
for(int i = 0; i < N; i++){
root -> update(l[i],r[i],i);
dn[i] = -1;
}
root -> pop(N - 1, 1);
while(!q.empty()){
pair<int,int> ii = q.front();
q.pop();
int i = ii.first;
if(dn[i] != -1) continue;
dn[i] = ii.second;
root -> pop(i,ii.second + 1);
}
scanf(" %d",&Q);
if(Q == 1){
printf("%d",dn[0]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
passport.cpp: In function 'int main()':
passport.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
passport.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf(" %d",&l[i]);
| ~~~~~^~~~~~~~~~~~~
passport.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | scanf(" %d",&r[i]);
| ~~~~~^~~~~~~~~~~~~
passport.cpp:110:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | scanf(" %d",&Q);
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |