# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54318 |
2018-07-03T06:54:28 Z |
윤교준(#1474) |
Sails (IOI07_sails) |
C++11 |
|
591 ms |
5692 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[22000022], *p=str;
const int MAXN = 100005;
const int MX = 131072;
struct SEG {
int d[MAXN*4], dmx[MAXN*4], dmn[MAXN*4];
void prop(int i, int s, int e) {
if(s == e) {
dmx[i] += d[i];
dmn[i] += d[i];
d[i] = 0;
} 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];
d[i*2] += d[i];
d[i*2+1] += d[i];
d[i] = 0;
}
}
void upd(int i, int s, int e, int p, int q, int r) {
prop(i, s, e); if(q < p || e < p || q < s) return;
if(p <= s && e <= q) {
d[i] += r;
prop(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);
prop(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) {
prop(i, s, e); 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);
prop(i, s, e);
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); }
void getV(vector<pair<int, pii>> &V, int i, int s, int e, int p, int q) {
prop(i, s, e); if(q < p || e < p || q < s) return;
if(p <= s && e <= q) { V.eb(i, pii(s, e)); return; }
int m = (s+e)/2;
getV(V, i*2, s, m, p, q);
getV(V, i*2+1, m+1, e, p, q);
prop(i, s, e);
}
int _getMN(int i, int s, int e, int h) {
prop(i, s, e); if(s == e) return s;
int m = (s+e)/2;
prop(i*2, s, m); prop(i*2+1, m+1, e);
if(dmn[i*2] != h) {
return _getMN(i*2, s, m, h);
} else {
return _getMN(i*2+1, m+1, e, h);
}
}
int getMN(int s, int e, int h) {
vector<pair<int, pii>> V;
getV(V, 1, 1, 100000, s, e);
if(dmn[V.back().first] == h) return e;
int i, S, E;
for(auto &v : V) {
if(dmn[v.first] == h) continue;
i = v.first;
tie(S, E) = v.second;
break;
}
return _getMN(i, S, E, h) - 1;
}
int _getMX(int i, int s, int e, int h) {
prop(i, s, e); if(s == e) return s;
int m = (s+e)/2;
prop(i*2, s, m); prop(i*2+1, m+1, e);
if(dmx[i*2+1] != h) {
return _getMX(i*2+1, m+1, e, h);
} else {
return _getMX(i*2, s, m, h);
}
}
int getMX(int s, int e, int h) {
vector<pair<int, pii>> V;
getV(V, 1, 1, 100000, s, e);
if(dmx[V[0].first] == h) return s;
revv(V);
int i, S, E;
for(auto &v : V) {
if(dmx[v.first] == h) continue;
i = v.first;
tie(S, E) = v.second;
break;
}
return _getMX(i, S, E, h) + 1;
}
} seg;
int C[MAXN];
int A[MAXN], B[MAXN];
ll Ans;
int N;
int main() {
//freopen("input.txt", "r", stdin);
fread(str, 1, 22000022, 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;
}
*/
su = seg.getMN(sx, ex, h);
sl = seg.getMX(1, sx, h);
//printf("%d : (%d %d) :: %d %d\n", i, sx, ex, sl, su);
{
int l = su-sx+1;
seg.upd(sl, sl+l-1, 1);
//printf("SEG %d %d\n", sl, sl+l-1);
}
seg.upd(su+1, ex, 1);
//printf("SEG %d %d\n", su+1, ex);
}
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:122: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, 22000022, stdin);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sails.cpp:120:5: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
int main() {
^~~~
sails.cpp:103:10: warning: 'S' may be used uninitialized in this function [-Wmaybe-uninitialized]
int i, S, E;
^
sails.cpp:103:7: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
int i, S, E;
^
sails.cpp:86:31: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
return _getMN(i, S, E, h) - 1;
^
sails.cpp:120:5: note: 'e' was declared here
int main() {
^~~~
sails.cpp:22:3: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(s == e) {
^~
sails.cpp:120:5: note: 's' was declared here
int main() {
^~~~
sails.cpp:79:7: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
int i, S, E;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
3576 KB |
Output is correct |
2 |
Correct |
55 ms |
3576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
3576 KB |
Output is correct |
2 |
Correct |
45 ms |
3576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
3576 KB |
Output is correct |
2 |
Correct |
44 ms |
3616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
3616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
3616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
4060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
160 ms |
4328 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
284 ms |
4728 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
591 ms |
5320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
433 ms |
5596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
468 ms |
5692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |