# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
202016 |
2020-02-13T04:55:46 Z |
manh9203 |
허수아비 (JOI14_scarecrows) |
C++17 |
|
1810 ms |
33732 KB |
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
const int N = 2e5 + 5;
typedef pair<int, int> point;
long long n, m, LBoard[N], RBoard[N], fen[N], ans;
point p[N];
vector<int> dmx, s, que[N], upd[N];
map<int, int> idx;
//BIT
void update(int id, int val){
for(int i = id; i <= m; i += (i&-i)){
fen[i] += val;
}
}
int get(int id){
int sum = 0;
for(int i = id; i >= 1; i -= (i&-i)){
sum += fen[i];
}
return sum;
}
//DnC
bool cmp1(point a, point b){
return a.y < b.y;
}
bool cmp2(point a, point b){
return a.x < b.x;
}
void solve(int l, int r){
if(l == r) return;
int mid = (l + r) >> 1;
dmx.clear(); idx.clear();
for(int i = l; i <= r; i++){
dmx.push_back(p[i].x);
}
sort(dmx.begin(), dmx.end());
auto it = unique(dmx.begin(), dmx.end());
dmx.resize(distance(dmx.begin(), it));
m = dmx.size();
for(int i = 0; i < m; i++){
idx[dmx[i]] = i + 1;
que[i + 1].clear(); upd[i + 1].clear();
fen[i + 1] = 0;
}
sort(p + l, p + mid + 1, cmp2);
sort(p + mid + 1, p + r + 1, cmp2);
s.clear(); s.push_back(0);
idx[-1] = m + 1;
for(int i = mid; i >= l; i--){
while(s.size() > 1 && p[i].y > p[s.back()].y){
s.pop_back();
}
upd[idx[p[s.back()].x]].push_back(idx[p[i].x]);
s.push_back(i);
update(idx[p[i].x], 1);
}
s.clear(); s.push_back(0);
idx[-1] = 0;
for(int i = mid + 1; i <= r; i++){
while(s.size() > 1 && p[i].y < p[s.back()].y){
s.pop_back();
}
que[idx[p[i].x]].push_back(idx[p[s.back()].x]);
s.push_back(i);
}
for(int i = 1; i <= m; i++){
for(int j: upd[i]){
update(j, -1);
}
for(int j: que[i]){
ans += get(i) - get(j);
}
}
sort(p + l, p + r + 1, cmp1);
solve(l, mid);
solve(mid + 1, r);
}
//main
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> p[i].x >> p[i].y;
}
p[0] = {-1, -1};
sort(p + 1, p + 1 + n, cmp1);
solve(1, n);
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9720 KB |
Output is correct |
3 |
Correct |
12 ms |
9848 KB |
Output is correct |
4 |
Correct |
12 ms |
9752 KB |
Output is correct |
5 |
Correct |
12 ms |
9720 KB |
Output is correct |
6 |
Correct |
12 ms |
9720 KB |
Output is correct |
7 |
Correct |
12 ms |
9720 KB |
Output is correct |
8 |
Correct |
12 ms |
9720 KB |
Output is correct |
9 |
Correct |
12 ms |
9720 KB |
Output is correct |
10 |
Correct |
12 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
10232 KB |
Output is correct |
2 |
Correct |
37 ms |
10360 KB |
Output is correct |
3 |
Correct |
33 ms |
10360 KB |
Output is correct |
4 |
Correct |
30 ms |
10488 KB |
Output is correct |
5 |
Correct |
35 ms |
10360 KB |
Output is correct |
6 |
Correct |
38 ms |
10364 KB |
Output is correct |
7 |
Correct |
37 ms |
10360 KB |
Output is correct |
8 |
Correct |
29 ms |
10292 KB |
Output is correct |
9 |
Correct |
34 ms |
10232 KB |
Output is correct |
10 |
Correct |
37 ms |
10360 KB |
Output is correct |
11 |
Correct |
38 ms |
10488 KB |
Output is correct |
12 |
Correct |
29 ms |
10232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1316 ms |
29168 KB |
Output is correct |
2 |
Correct |
1783 ms |
31672 KB |
Output is correct |
3 |
Correct |
1551 ms |
32112 KB |
Output is correct |
4 |
Correct |
1270 ms |
33732 KB |
Output is correct |
5 |
Correct |
1616 ms |
32752 KB |
Output is correct |
6 |
Correct |
1696 ms |
31980 KB |
Output is correct |
7 |
Correct |
1779 ms |
31852 KB |
Output is correct |
8 |
Correct |
1779 ms |
31856 KB |
Output is correct |
9 |
Correct |
1285 ms |
30576 KB |
Output is correct |
10 |
Correct |
1530 ms |
31088 KB |
Output is correct |
11 |
Correct |
1645 ms |
31596 KB |
Output is correct |
12 |
Correct |
1737 ms |
31732 KB |
Output is correct |
13 |
Correct |
1810 ms |
31728 KB |
Output is correct |
14 |
Correct |
1295 ms |
30572 KB |
Output is correct |
15 |
Correct |
1646 ms |
31596 KB |
Output is correct |
16 |
Correct |
1794 ms |
31752 KB |
Output is correct |
17 |
Correct |
1043 ms |
24304 KB |
Output is correct |
18 |
Correct |
1779 ms |
31728 KB |
Output is correct |
19 |
Correct |
1769 ms |
31728 KB |
Output is correct |
20 |
Correct |
1777 ms |
31596 KB |
Output is correct |