# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63313 | 2018-08-01T10:48:08 Z | kjp4155 | None (KOI18_XCorr) | C++17 | 292 ms | 30816 KB |
#include <stdio.h> #include <algorithm> #include <utility> #include <vector> using namespace std; typedef long long ll; const ll inf = 1e18; int N,M; int a,b; // 수열 X,Y의 (index, value) 쌍을 저장한다. S에는 Y의 누적합 배열을 저장한다 vector<pair<ll,ll>> X,Y,S; int main(){ scanf("%d",&N); for(int i=0;i<N;i++){ ll idx, val; scanf("%lld%lld",&idx,&val); X.push_back(make_pair(idx,val)); } scanf("%d",&M); for(int i=0;i<M;i++){ ll idx, val; scanf("%lld%lld",&idx,&val); Y.push_back(make_pair(idx,val)); } scanf("%d%d",&a,&b); // Y의 누적합 배열 S를 계산한다 S.resize(M); for(int i=0;i<M;i++){ S[i] = Y[i]; if( i > 0 ) S[i].second += S[i-1].second; } ll ans = 0; for(int i=0;i<N;i++){ ll idx = X[i].first, val = X[i].second; // X[i]와 관련있는 Y값들의 합을 sum에 저장하자 ll sum = 0; // idx+b 에 해당하는 누적합 배열의 우측 값을 구하자. // 이분탐색 결과로 나온 iterator가 S.begin()인 경우를 유의한다. (it1-- 에서 런타임 에러 발생 가능) // idx+b 가 음수라 [idx+a, idx+b]에 해당하는 y값들이 모두 0인 경우 넘어간다 auto it1 = upper_bound(S.begin(), S.end(), make_pair(idx+b, inf)); if( it1 == S.begin() ) continue; it1--; sum += (*it1).second; // idx+a-1 에 해당하는 누적합 배열의 좌측 값을 구하자 // 이분탐색 결과로 나온 iterator가 S.begin()인 경우를 유의한다. (it2-- 에서 런타임 에러 발생 가능) auto it2 = lower_bound(S.begin(), S.end(), make_pair(idx+a, -inf)); if( it2 != S.begin() ) { it2--; sum -= (*it2).second; } // 답에 X[i] * (관련있는 모든 Y값의 합) 를 더해 준다 ans += sum * val; } printf("%lld\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 6 ms | 668 KB | Output is correct |
3 | Correct | 5 ms | 792 KB | Output is correct |
4 | Correct | 3 ms | 792 KB | Output is correct |
5 | Correct | 2 ms | 792 KB | Output is correct |
6 | Correct | 5 ms | 876 KB | Output is correct |
7 | Correct | 4 ms | 984 KB | Output is correct |
8 | Correct | 4 ms | 1040 KB | Output is correct |
9 | Correct | 4 ms | 1040 KB | Output is correct |
10 | Correct | 5 ms | 1076 KB | Output is correct |
11 | Correct | 2 ms | 1076 KB | Output is correct |
12 | Correct | 5 ms | 1172 KB | Output is correct |
13 | Correct | 5 ms | 1228 KB | Output is correct |
14 | Correct | 3 ms | 1228 KB | Output is correct |
15 | Correct | 3 ms | 1228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 6 ms | 668 KB | Output is correct |
3 | Correct | 5 ms | 792 KB | Output is correct |
4 | Correct | 3 ms | 792 KB | Output is correct |
5 | Correct | 2 ms | 792 KB | Output is correct |
6 | Correct | 5 ms | 876 KB | Output is correct |
7 | Correct | 4 ms | 984 KB | Output is correct |
8 | Correct | 4 ms | 1040 KB | Output is correct |
9 | Correct | 4 ms | 1040 KB | Output is correct |
10 | Correct | 5 ms | 1076 KB | Output is correct |
11 | Correct | 2 ms | 1076 KB | Output is correct |
12 | Correct | 5 ms | 1172 KB | Output is correct |
13 | Correct | 5 ms | 1228 KB | Output is correct |
14 | Correct | 3 ms | 1228 KB | Output is correct |
15 | Correct | 3 ms | 1228 KB | Output is correct |
16 | Correct | 113 ms | 12552 KB | Output is correct |
17 | Correct | 4 ms | 12552 KB | Output is correct |
18 | Correct | 235 ms | 20812 KB | Output is correct |
19 | Correct | 4 ms | 20812 KB | Output is correct |
20 | Correct | 4 ms | 20812 KB | Output is correct |
21 | Correct | 4 ms | 20812 KB | Output is correct |
22 | Correct | 3 ms | 20812 KB | Output is correct |
23 | Correct | 4 ms | 20812 KB | Output is correct |
24 | Correct | 228 ms | 20812 KB | Output is correct |
25 | Correct | 272 ms | 21032 KB | Output is correct |
26 | Correct | 264 ms | 21032 KB | Output is correct |
27 | Correct | 5 ms | 21032 KB | Output is correct |
28 | Correct | 5 ms | 21032 KB | Output is correct |
29 | Correct | 4 ms | 21032 KB | Output is correct |
30 | Correct | 264 ms | 25212 KB | Output is correct |
31 | Correct | 4 ms | 25212 KB | Output is correct |
32 | Correct | 292 ms | 25244 KB | Output is correct |
33 | Correct | 195 ms | 25424 KB | Output is correct |
34 | Correct | 134 ms | 25424 KB | Output is correct |
35 | Correct | 2 ms | 25424 KB | Output is correct |
36 | Correct | 219 ms | 25424 KB | Output is correct |
37 | Correct | 77 ms | 25424 KB | Output is correct |
38 | Correct | 4 ms | 25424 KB | Output is correct |
39 | Correct | 230 ms | 25424 KB | Output is correct |
40 | Correct | 5 ms | 25424 KB | Output is correct |
41 | Correct | 2 ms | 25424 KB | Output is correct |
42 | Correct | 4 ms | 25424 KB | Output is correct |
43 | Correct | 3 ms | 25424 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 6 ms | 668 KB | Output is correct |
3 | Correct | 5 ms | 792 KB | Output is correct |
4 | Correct | 3 ms | 792 KB | Output is correct |
5 | Correct | 2 ms | 792 KB | Output is correct |
6 | Correct | 5 ms | 876 KB | Output is correct |
7 | Correct | 4 ms | 984 KB | Output is correct |
8 | Correct | 4 ms | 1040 KB | Output is correct |
9 | Correct | 4 ms | 1040 KB | Output is correct |
10 | Correct | 5 ms | 1076 KB | Output is correct |
11 | Correct | 2 ms | 1076 KB | Output is correct |
12 | Correct | 5 ms | 1172 KB | Output is correct |
13 | Correct | 5 ms | 1228 KB | Output is correct |
14 | Correct | 3 ms | 1228 KB | Output is correct |
15 | Correct | 3 ms | 1228 KB | Output is correct |
16 | Correct | 113 ms | 12552 KB | Output is correct |
17 | Correct | 4 ms | 12552 KB | Output is correct |
18 | Correct | 235 ms | 20812 KB | Output is correct |
19 | Correct | 4 ms | 20812 KB | Output is correct |
20 | Correct | 4 ms | 20812 KB | Output is correct |
21 | Correct | 4 ms | 20812 KB | Output is correct |
22 | Correct | 3 ms | 20812 KB | Output is correct |
23 | Correct | 4 ms | 20812 KB | Output is correct |
24 | Correct | 228 ms | 20812 KB | Output is correct |
25 | Correct | 272 ms | 21032 KB | Output is correct |
26 | Correct | 264 ms | 21032 KB | Output is correct |
27 | Correct | 5 ms | 21032 KB | Output is correct |
28 | Correct | 5 ms | 21032 KB | Output is correct |
29 | Correct | 4 ms | 21032 KB | Output is correct |
30 | Correct | 264 ms | 25212 KB | Output is correct |
31 | Correct | 4 ms | 25212 KB | Output is correct |
32 | Correct | 292 ms | 25244 KB | Output is correct |
33 | Correct | 195 ms | 25424 KB | Output is correct |
34 | Correct | 134 ms | 25424 KB | Output is correct |
35 | Correct | 2 ms | 25424 KB | Output is correct |
36 | Correct | 219 ms | 25424 KB | Output is correct |
37 | Correct | 77 ms | 25424 KB | Output is correct |
38 | Correct | 4 ms | 25424 KB | Output is correct |
39 | Correct | 230 ms | 25424 KB | Output is correct |
40 | Correct | 5 ms | 25424 KB | Output is correct |
41 | Correct | 2 ms | 25424 KB | Output is correct |
42 | Correct | 4 ms | 25424 KB | Output is correct |
43 | Correct | 3 ms | 25424 KB | Output is correct |
44 | Correct | 112 ms | 25424 KB | Output is correct |
45 | Correct | 4 ms | 25424 KB | Output is correct |
46 | Correct | 189 ms | 25424 KB | Output is correct |
47 | Correct | 4 ms | 25424 KB | Output is correct |
48 | Correct | 167 ms | 25424 KB | Output is correct |
49 | Correct | 101 ms | 25424 KB | Output is correct |
50 | Correct | 5 ms | 25424 KB | Output is correct |
51 | Correct | 5 ms | 25424 KB | Output is correct |
52 | Correct | 3 ms | 25424 KB | Output is correct |
53 | Correct | 7 ms | 25424 KB | Output is correct |
54 | Correct | 215 ms | 25424 KB | Output is correct |
55 | Correct | 194 ms | 25424 KB | Output is correct |
56 | Correct | 215 ms | 25424 KB | Output is correct |
57 | Correct | 205 ms | 25424 KB | Output is correct |
58 | Correct | 268 ms | 25424 KB | Output is correct |
59 | Correct | 4 ms | 25424 KB | Output is correct |
60 | Correct | 2 ms | 25424 KB | Output is correct |
61 | Correct | 5 ms | 25424 KB | Output is correct |
62 | Correct | 241 ms | 25424 KB | Output is correct |
63 | Correct | 230 ms | 30088 KB | Output is correct |
64 | Correct | 3 ms | 30088 KB | Output is correct |
65 | Correct | 202 ms | 30816 KB | Output is correct |
66 | Correct | 179 ms | 30816 KB | Output is correct |
67 | Correct | 214 ms | 30816 KB | Output is correct |
68 | Correct | 5 ms | 30816 KB | Output is correct |
69 | Correct | 211 ms | 30816 KB | Output is correct |
70 | Correct | 118 ms | 30816 KB | Output is correct |
71 | Correct | 218 ms | 30816 KB | Output is correct |
72 | Correct | 192 ms | 30816 KB | Output is correct |
73 | Correct | 85 ms | 30816 KB | Output is correct |
74 | Correct | 3 ms | 30816 KB | Output is correct |
75 | Correct | 224 ms | 30816 KB | Output is correct |
76 | Correct | 72 ms | 30816 KB | Output is correct |
77 | Correct | 6 ms | 30816 KB | Output is correct |
78 | Correct | 174 ms | 30816 KB | Output is correct |
79 | Correct | 2 ms | 30816 KB | Output is correct |
80 | Correct | 4 ms | 30816 KB | Output is correct |
81 | Correct | 3 ms | 30816 KB | Output is correct |
82 | Correct | 214 ms | 30816 KB | Output is correct |
83 | Correct | 3 ms | 30816 KB | Output is correct |
84 | Correct | 3 ms | 30816 KB | Output is correct |
85 | Correct | 267 ms | 30816 KB | Output is correct |