Submission #856608
Source Code Expand
Copy
#include <cstdio>
#include <vector>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
vector<int> s;
typedef struct node{
int pos,dist,p;
vector<pair<int,int> > queries;
vector<int> v;
};
node arr[110000];
int ans[110000]={};
deque<pair<int,int> >dq;
void dfs(int x,int lv){
arr[x].dist=lv;
for(auto &it:arr[x].v){
dfs(it,lv+1);
}
}
void dfs2(int x){
s.push_back(x);
for(auto &it: arr[x].queries){
ans[it.second]=arr[x].dist-arr[it.first].dist+(arr[s[arr[it.first].dist]].pos<arr[it.first].pos);
}
for(auto &it:arr[x].v){
dfs2(it);
}
s.pop_back();
}
int main(){
int n,l;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&arr[i].pos);
}
scanf("%d",&l);
for(int i=1;i<=n;i++){
dq.push_back({arr[i].pos,i});
while(arr[i].pos>dq.front().first+l){
arr[dq.front().second].p=i-1;
dq.pop_front();
}
}
while(!dq.empty()){
arr[dq.front().second].p=n;
dq.pop_front();
}
for(int i=1;i<n;i++){
arr[arr[i].p].v.push_back(i);
}
int q,a,b;
scanf("%d",&q);
for(int i=1;i<=q;i++){
scanf("%d %d",&a,&b);
if(a>b)swap(a,b);
arr[a].queries.push_back({b,i});
}
dfs(n,0);
dfs2(n);
for(int i=1;i<=q;i++){
printf("%d\n",ans[i]);
}
}
Submission Info
Submission Time
2016-08-28 22:12:49+0900
Task
E - Tak and Hotels
User
VoSK
Language
C++14 (GCC 5.4.1)
Score
700
Code Size
1264 Byte
Status
AC
Exec Time
136 ms
Memory
18424 KB
Compile Error
./Main.cpp:12:1: warning: ‘typedef’ was ignored in this declaration
};
^
./Main.cpp: In function ‘int main()’:
./Main.cpp:34:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:36:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&arr[i].pos);
^
./Main.cpp:38:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&l);
^
./Main.cpp:54:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&q);
^
./Main.cpp:56:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a,&b...
Judge Result
Set Name
Sample
Subtask1
All
Score / Max Score
0 / 0
200 / 200
500 / 500
Status
Set Name
Test Cases
Sample
example_01.txt
Subtask1
example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt
All
example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt
Case Name
Status
Exec Time
Memory
example_01.txt
AC
15 ms
7168 KB
subtask1_01.txt
AC
14 ms
7168 KB
subtask1_02.txt
AC
15 ms
7168 KB
subtask1_03.txt
AC
15 ms
7168 KB
subtask1_04.txt
AC
15 ms
7168 KB
subtask1_05.txt
AC
16 ms
7168 KB
subtask1_06.txt
AC
14 ms
7168 KB
subtask1_07.txt
AC
14 ms
7168 KB
subtask1_08.txt
AC
14 ms
7168 KB
subtask1_09.txt
AC
15 ms
7168 KB
subtask1_10.txt
AC
16 ms
7168 KB
subtask1_11.txt
AC
15 ms
7168 KB
subtask1_12.txt
AC
16 ms
7168 KB
subtask1_13.txt
AC
15 ms
7168 KB
subtask2_01.txt
AC
136 ms
13440 KB
subtask2_02.txt
AC
129 ms
18424 KB
subtask2_03.txt
AC
128 ms
13056 KB
subtask2_04.txt
AC
70 ms
9088 KB
subtask2_05.txt
AC
85 ms
10368 KB
subtask2_06.txt
AC
104 ms
10112 KB
subtask2_07.txt
AC
124 ms
12160 KB
subtask2_08.txt
AC
126 ms
15740 KB
subtask2_09.txt
AC
129 ms
15740 KB
subtask2_10.txt
AC
131 ms
15740 KB
subtask2_11.txt
AC
123 ms
15232 KB
subtask2_12.txt
AC
109 ms
17796 KB
subtask2_13.txt
AC
106 ms
10112 KB