# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1067322 |
2024-08-20T14:46:12 Z |
juicy |
허수아비 (JOI14_scarecrows) |
C++17 |
|
926 ms |
16868 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n;
long long res;
int ft[N], p[N];
void upd(int i, int x) {
for (; i <= n; i += i & -i) {
ft[i] += x;
}
}
int qry(int i) {
int res = 0;
for (; i; i -= i & -i) {
res += ft[i];
}
return res;
}
int qry(int l, int r) {
return qry(r) - qry(l - 1);
}
void add(int x) {
if (x > 0) {
upd(x, 1);
} else {
upd(-x, -1);
}
}
void dc(int L, int R) {
if (L == R) {
return;
}
int md = (L + R) / 2;
dc(L, md); dc(md + 1, R);
set<int> st;
vector<array<int, 2>> queries, events;
for (int i = md + 1; i <= R; ++i) {
auto it = st.upper_bound(p[i]);
int j = it != st.begin() ? *prev(it) + 1 : 1;
queries.push_back({p[i], j});
st.insert(p[i]);
}
set<int>().swap(st);
for (int i = md; i >= L; --i) {
auto it = st.lower_bound(p[i]);
int j = it != st.end() ? *it : n + 1;
events.push_back({p[i], p[i]});
events.push_back({j, -p[i]});
st.insert(p[i]);
}
set<int>().swap(st);
sort(queries.begin(), queries.end());
sort(events.begin(), events.end());
int j = 0;
for (auto [r, l] : queries) {
while (j < events.size() && events[j][0] <= r) {
add(events[j++][1]);
}
res += qry(l, r);
}
while (j < events.size()) {
add(events[j++][1]);
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n;
vector<array<int, 2>> pt(n);
vector<int> comp;
for (int i = 0; i < n; ++i) {
cin >> pt[i][0] >> pt[i][1];
comp.push_back(pt[i][1]);
}
sort(pt.begin(), pt.end());
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
for (int i = 0; i < n; ++i) {
p[i] = lower_bound(comp.begin(), comp.end(), pt[i][1]) - comp.begin() + 1;
}
dc(0, n - 1);
cout << res;
return 0;
}
Compilation message
scarecrows.cpp: In function 'void dc(int, int)':
scarecrows.cpp:70:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | while (j < events.size() && events[j][0] <= r) {
| ~~^~~~~~~~~~~~~~~
scarecrows.cpp:75:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | while (j < events.size()) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
828 KB |
Output is correct |
2 |
Correct |
13 ms |
860 KB |
Output is correct |
3 |
Correct |
11 ms |
776 KB |
Output is correct |
4 |
Correct |
7 ms |
856 KB |
Output is correct |
5 |
Correct |
12 ms |
856 KB |
Output is correct |
6 |
Correct |
12 ms |
860 KB |
Output is correct |
7 |
Correct |
13 ms |
856 KB |
Output is correct |
8 |
Correct |
8 ms |
872 KB |
Output is correct |
9 |
Correct |
12 ms |
860 KB |
Output is correct |
10 |
Correct |
12 ms |
860 KB |
Output is correct |
11 |
Correct |
13 ms |
744 KB |
Output is correct |
12 |
Correct |
9 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
515 ms |
13848 KB |
Output is correct |
2 |
Correct |
918 ms |
16796 KB |
Output is correct |
3 |
Correct |
686 ms |
15056 KB |
Output is correct |
4 |
Correct |
479 ms |
15056 KB |
Output is correct |
5 |
Correct |
730 ms |
15272 KB |
Output is correct |
6 |
Correct |
807 ms |
15092 KB |
Output is correct |
7 |
Correct |
879 ms |
16512 KB |
Output is correct |
8 |
Correct |
926 ms |
16732 KB |
Output is correct |
9 |
Correct |
526 ms |
15168 KB |
Output is correct |
10 |
Correct |
755 ms |
15284 KB |
Output is correct |
11 |
Correct |
852 ms |
15072 KB |
Output is correct |
12 |
Correct |
873 ms |
16348 KB |
Output is correct |
13 |
Correct |
915 ms |
16868 KB |
Output is correct |
14 |
Correct |
530 ms |
15192 KB |
Output is correct |
15 |
Correct |
821 ms |
16212 KB |
Output is correct |
16 |
Correct |
923 ms |
16604 KB |
Output is correct |
17 |
Correct |
528 ms |
9984 KB |
Output is correct |
18 |
Correct |
875 ms |
15392 KB |
Output is correct |
19 |
Correct |
856 ms |
15276 KB |
Output is correct |
20 |
Correct |
868 ms |
15064 KB |
Output is correct |