# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
99734 |
2019-03-06T11:13:45 Z |
songc |
허수아비 (JOI14_scarecrows) |
C++14 |
|
752 ms |
67532 KB |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int N;
long long ans;
pii A[202020];
struct Node{
vector<pii> V;
Node *lc=NULL, *rc=NULL;
};
void update(Node *now, int s, int e, pii P){
if (e < P.second || P.second < s) return;
if (s == e) {
now->V.push_back(P);
return;
}
int mid = (s+e)/2;
if (now->lc == NULL) now->lc = new Node;
update(now->lc, s, mid, P);
if (now->rc == NULL) now->rc = new Node;
update(now->rc, mid+1, e, P);
while (!now->V.empty() && now->V.back().second < P.second) now->V.pop_back();
now->V.push_back(P);
}
int query(Node *now, int s, int e, int xlim, int ylim){
if (ylim < s) return xlim;
if (e <= ylim){
auto k = lower_bound(now->V.begin(), now->V.end(), pii(xlim, 0));
if (k == now->V.end()) return xlim;
ans += now->V.end() - k;
return now->V.back().first;
}
int mid = (s+e)/2;
if (now->rc != NULL) xlim = query(now->rc, mid+1, e, xlim, ylim);
if (now->lc != NULL) xlim = query(now->lc, s, mid, xlim, ylim);
return xlim;
}
int main(){
scanf("%d", &N);
for (int i=1; i<=N; i++) scanf("%d %d", &A[i].first, &A[i].second);
sort(A+1, A+N+1, [&](pii X, pii Y){
return X.second < Y.second;
});
for (int i=1; i<=N; i++) A[i].second = i;
sort(A+1, A+N+1);
Node *Tree = new Node;
for (int i=1; i<=N; i++){
query(Tree, 1, N, 0, A[i].second);
update(Tree, 1, N, A[i]);
}
printf("%lld\n", ans);
return 0;
}
Compilation message
scarecrows.cpp: In function 'int main()':
scarecrows.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
scarecrows.cpp:46:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=N; i++) scanf("%d %d", &A[i].first, &A[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1792 KB |
Output is correct |
2 |
Correct |
13 ms |
1280 KB |
Output is correct |
3 |
Correct |
11 ms |
1536 KB |
Output is correct |
4 |
Correct |
8 ms |
1280 KB |
Output is correct |
5 |
Correct |
11 ms |
1252 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
12 ms |
1380 KB |
Output is correct |
8 |
Correct |
9 ms |
1920 KB |
Output is correct |
9 |
Correct |
10 ms |
1408 KB |
Output is correct |
10 |
Correct |
11 ms |
1308 KB |
Output is correct |
11 |
Correct |
13 ms |
1252 KB |
Output is correct |
12 |
Correct |
5 ms |
1252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
65336 KB |
Output is correct |
2 |
Correct |
649 ms |
39072 KB |
Output is correct |
3 |
Correct |
311 ms |
51548 KB |
Output is correct |
4 |
Correct |
200 ms |
37044 KB |
Output is correct |
5 |
Correct |
326 ms |
37688 KB |
Output is correct |
6 |
Correct |
462 ms |
38688 KB |
Output is correct |
7 |
Correct |
602 ms |
38880 KB |
Output is correct |
8 |
Correct |
615 ms |
38988 KB |
Output is correct |
9 |
Correct |
340 ms |
67532 KB |
Output is correct |
10 |
Correct |
395 ms |
45960 KB |
Output is correct |
11 |
Correct |
520 ms |
40608 KB |
Output is correct |
12 |
Correct |
628 ms |
39312 KB |
Output is correct |
13 |
Correct |
752 ms |
39072 KB |
Output is correct |
14 |
Correct |
337 ms |
66348 KB |
Output is correct |
15 |
Correct |
551 ms |
40652 KB |
Output is correct |
16 |
Correct |
715 ms |
39176 KB |
Output is correct |
17 |
Correct |
299 ms |
27040 KB |
Output is correct |
18 |
Correct |
497 ms |
39056 KB |
Output is correct |
19 |
Correct |
401 ms |
39096 KB |
Output is correct |
20 |
Correct |
466 ms |
39052 KB |
Output is correct |