Submission #02287


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int INF = 1 << 30;
int main()
{
int64 N, T, Q;
vector< int64 > GoPlus, GoMinus;
int64 A[100000], B[100000];
cin >> N >> T >> Q;
GoPlus.push_back(-3000000000000000000LL);
for(int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
if(B[i] == 1LL) GoPlus.push_back(A[i]);
else GoMinus.push_back(A[i]);
}
GoMinus.push_back(3000000000000000000LL);
for(int i = 0; i < Q; i++) {
int64 X;
cin >> X;
--X;
if(B[X] == 1LL) {
vector< int64 >::iterator it = lower_bound(GoMinus.begin(), GoMinus.end(), A[X]);
if(it == GoMinus.end() - 1) {
cout << A[X] + T << endl;
continue;
}
vector< int64 >::iterator STOP = --lower_bound(GoPlus.begin(), GoPlus.end(), *it);
int64 POS = (*it + *STOP) / 2LL;
if(A[X] + T <= POS) {
cout << A[X] + T << endl;
} else {
cout << POS << endl;
}
} else {
vector< int64 >::iterator it = --lower_bound(GoPlus.begin(), GoPlus.end(), A[X]);
if(it == GoPlus.begin()) {
cout << A[X] - T << endl;
continue;
}
vector< int64 >::iterator STOP = lower_bound(GoMinus.begin(), GoMinus.end(), *it);
int64 POS = (*STOP + *it) / 2LL;
if(A[X] - T >= POS) {
cout << A[X] - T << endl;
} else {
cout << POS << endl;
}
}
}
}

ステータス

項目 データ
問題 0260 - JOI国のお散歩事情 (Walking in JOI Kingdom)
ユーザー名 ei1333
投稿日時 2015-12-14 15:36:21
言語 C++11
状態 Accepted
得点 5
ソースコード長 1477 Byte
最大実行時間 89 ms
最大メモリ使用量 3108 KB

セット

セット 得点 Cases
1 INPUT1 1 / 1 *in1.txt
2 INPUT2 1 / 1 *in2.txt
3 INPUT3 1 / 1 *in3.txt
4 INPUT4 1 / 1 *in4.txt
5 INPUT5 1 / 1 *in5.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
2016-yo-t4-in1.txt AC 12 ms 476 KB
1
2016-yo-t4-in2.txt AC 17 ms 820 KB
2
2016-yo-t4-in3.txt AC 56 ms 2928 KB
3
2016-yo-t4-in4.txt AC 78 ms 3108 KB
4
2016-yo-t4-in5.txt AC 89 ms 3032 KB
5
2016-yo-t4-in_s1.txt AC 13 ms 572 KB
2016-yo-t4-in_s2.txt AC 10 ms 668 KB