# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54300 |
2018-07-03T06:23:00 Z |
윤교준(#1474) |
Sails (IOI07_sails) |
C++11 |
|
1000 ms |
5828 KB |
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#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;
static unsigned char str[55000055], *p=str;
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);
fread(str, 1, 55000055, stdin);
rf(N)
{
vector<pii> V;
for(int i = 1, a, b; i <= N; i++) {
rf(a) rf(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;
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:60:7: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
fread(str, 1, 55000055, stdin);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
376 KB |
Output is correct |
2 |
Correct |
19 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
500 KB |
Output is correct |
2 |
Correct |
18 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
588 KB |
Output is correct |
2 |
Correct |
19 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
600 KB |
Output is correct |
2 |
Correct |
21 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
824 KB |
Output is correct |
2 |
Correct |
31 ms |
3640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
3640 KB |
Output is correct |
2 |
Correct |
202 ms |
3640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
3640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
595 ms |
3640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
5460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
867 ms |
5744 KB |
Output is correct |
2 |
Correct |
567 ms |
5744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
5828 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |