# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54299 |
2018-07-03T06:21:30 Z |
윤교준(#1474) |
Sails (IOI07_sails) |
C++11 |
|
1000 ms |
4704 KB |
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 100005;
const int MX = 131072;
struct SEG {
int d[MAXN*3], dmx[MAXN*3], dmn[MAXN*3];
void _upd(int i, int s, int e) {
if(s == e) {
dmx[i] = dmn[i] = d[i];
} else {
dmx[i] = max(dmx[i*2], dmx[i*2+1]) + d[i];
dmn[i] = min(dmn[i*2], dmn[i*2+1]) + d[i];
}
}
void upd(int i, int s, int e, int p, int q, int r) {
if(q < p || e < p || q < s) return;
if(p <= s && e <= q) {
d[i] += r;
_upd(i, s, e);
return;
}
int m = (s+e)/2;
upd(i*2, s, m, p, q, r);
upd(i*2+1, m+1, e, p, q, r);
_upd(i, s, e);
}
void upd(int s, int e, int x) { upd(1, 1, 100000, s, e, x); }
pii get(int i, int s, int e, int p, int q) {
if(q < p || e < p || q < s) return pii(-INF, INF);
if(p <= s && e <= q) return pii(dmx[i], dmn[i]);
int m = (s+e)/2;
pii l = get(i*2, s, m, p, q), r = get(i*2+1, m+1, e, p, q);
return pii(max(l.first, r.first) + d[i], min(l.second, r.second) + d[i]);
}
pii get(int s, int e) { return get(1, 1, 100000, s, e); }
} seg;
int C[MAXN];
int A[MAXN], B[MAXN];
ll Ans;
int N;
int main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin >> N;
{
vector<pii> V;
for(int i = 1, a, b; i <= N; i++) {
cin >> a >> b;
V.eb(a, b);
}
sorv(V);
for(int i = 0; i < N; i++)
tie(A[i+1], B[i+1]) = V[i];
}
for(int i = 1; i <= N; i++) {
int ex = A[i], sx = ex-B[i]+1;
int sl = sx, su = sx;
int h = seg.get(sx, sx).first;
//printf("i=%d, h=%d : %d %d\n", i, h, sx, ex);
{
int s = sx, e = ex; for(int m; s < e;) {
m = (s+e+1)/2;
if(seg.get(sx, m).second < h) e = m-1;
else s = m;
}
su = s;
}
{
int s = 1, e = sx; for(int m; s < e;) {
m = (s+e)/2;
if(seg.get(m, sx).first > h) s = m+1;
else e = m;
}
sl = s;
}
//printf("%d : (%d %d) :: %d %d\n", i, sx, ex, sl, su);
{
int l = su-sx+1;
seg.upd(sl, sl+l-1, 1);
}
seg.upd(su+1, ex, 1);
}
for(int i = 1; i <= 100000; i++) {
int c = seg.get(i, i).first;
//if(i <= 10) printf("%d : %d\n", i, c);
Ans += ll(c) * (c-1) / 2;
}
cout << Ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
504 KB |
Output is correct |
2 |
Correct |
18 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
612 KB |
Output is correct |
2 |
Correct |
18 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
612 KB |
Output is correct |
2 |
Correct |
18 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
648 KB |
Output is correct |
2 |
Correct |
21 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
920 KB |
Output is correct |
2 |
Correct |
31 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
3620 KB |
Output is correct |
2 |
Correct |
224 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
492 ms |
3620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
990 ms |
4520 KB |
Output is correct |
2 |
Correct |
798 ms |
4520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
848 ms |
4704 KB |
Output is correct |
2 |
Correct |
528 ms |
4704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1084 ms |
4704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |