# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54554 |
2018-07-04T05:13:08 Z |
윤교준(#1492) |
Pairs (IOI07_pairs) |
C++11 |
|
338 ms |
65188 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 univ(V) (V).erase(unique(allv(V)))
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
namespace TC1 {
int A[100005];
ll Ans;
int N, L, M;
void init(int _N, int _L, int _M) {
N = _N; L = _L; M = _M;
Ans = 0;
}
void run() {
for(int i = 1; i <= N; i++) cin >> A[i];
sort(A+1, A+N+1);
for(int i = 1, j = 1; i <= N; i++) {
for(; j <= N && A[j] <= A[i]+L; j++);
Ans += j-i-1;
}
cout << Ans << endl;
}
};
namespace TC2 {
struct EVT {
EVT(int type, int x, int y) : type(type), x(x), y(y) {}
int type, x, y;
bool operator < (const EVT &t) const {
if(x != t.x) return x < t.x;
if(type != t.type) return type < t.type;
return y < t.type;
}
};
const static int MX = 262144;
struct SEG {
SEG() { init(); }
int d[MX*2];
void init() { fill(d, d+MX*2, 0); }
void upd(int x, int r) {
for(x += 75000 + MX; x; x /= 2)
d[x] += r;
}
int get(int s, int e) {
int r = 0;
s += 75000; e += 75000;
s = max(1, s); e = min(75000*2, e);
for(s += MX, e += MX; s <= e; s /= 2, e /= 2) {
if(s&1) r += d[s++];
if(~e&1) r += d[e--];
}
return r;
}
} seg;
vector<EVT> EV;
int X[100005], Y[100005];
ll Ans;
int N, L, M;
void init(int _N, int _L, int _M) {
N = _N; L = _L; M = _M;
Ans = 0;
}
void run() {
{
vector<pii> V;
for(int i = 1, x, y; i <= N; i++) {
cin >> x >> y;
V.eb(x+y, y-x);
}
sorv(V);
for(int i = 1; i <= N; i++)
tie(X[i], Y[i]) = V[i-1];
}
for(int i = 1; i <= N; i++) {
EV.eb(2, X[i], Y[i]);
EV.eb(1, X[i]+L+1, Y[i]);
}
sorv(EV);
for(auto &e : EV) {
if(2 == e.type) {
Ans += seg.get(e.y - L, e.y + L);
seg.upd(e.y, 1);
} else {
seg.upd(e.y, -1);
}
}
cout << Ans << endl;
}
};
namespace TC3 {
const static int MX = 75*3 + 5;
struct BIT {
int d[MX][MX][MX];
void init() {
for(int i = 0; i < MX; i++)
for(int j = 0; j < MX; j++)
fill(d[i][j], d[i][j]+MX, 0);
}
void upd(int x, int y, int z, int r) {
x++; y++; z++;
for(int i = x; i < MX; i += rb(i))
for(int j = y; j < MX; j += rb(j))
for(int k = z; k < MX; k += rb(k))
d[i][j][k] += r;
}
int get(int x, int y, int z) {
x++; y++; z++;
int r = 0;
for(int i = x; i; i -= rb(i))
for(int j = y; j; j -= rb(j))
for(int k = z; k; k -= rb(k))
r += d[i][j][k];
return r;
}
} bit;
struct EVT {
EVT(int type, int x, int y, int z, int t) : type(type), x(x), y(y), z(z), t(t) {}
int type, x, y, z, t;
bool operator < (const EVT &tt) const {
if(x != tt.x) return x < tt.x;
if(type != tt.type) return type < tt.type;
if(t != tt.t) return t < tt.t;
return pii(y, z) < pii(tt.y, tt.z);
}
};
int ff(int x, int y, int z) {
x = min(75*3, max(0, x));
y = min(75*3, max(0, y));
z = min(75*3, max(0, z));
return bit.get(x, y, z);
}
int f(int sx, int sy, int sz, int ex, int ey, int ez) {
sx--; sy--; sz--;
return ff(ex, ey, ez) - ff(sx, ey, ez) - ff(ex, sy, ez) - ff(ex, ey, sz)
+ ff(sx, sy, ez) + ff(sx, ey, sz) + ff(ex, sy, sz) - ff(sx, sy, sz);
}
vector<EVT> VE;
int X[100005], Y[100005], Z[100005], T[100005];
ll Ans;
int N, L, M;
void init(int _N, int _L, int _M) {
N = _N; L = _L; M = _M;
}
void run() {
{
vector<pair<pii, pii>> V;
for(int i = 1, x, y, z; i <= N; i++) {
cin >> x >> y >> z;
V.eb(pii(x+y+z, x+y-z), pii(x-y+z, x-y-z));
}
sorv(V);
for(int i = 1; i <= N; i++) {
tie(X[i], T[i]) = V[i-1].first;
tie(Y[i], Z[i]) = V[i-1].second;
}
}
for(int i = 1; i <= N; i++) {
T[i] += 75;
Y[i] += 75;
Z[i] += 150;
}
for(int i = 1; i <= N; i++) {
VE.eb(2, X[i], Y[i], Z[i], T[i]);
VE.eb(1, X[i]+L+1, Y[i], Z[i], T[i]);
}
sorv(VE);
for(auto &e : VE) {
if(2 == e.type) {
Ans += f(e.y-L, e.z-L, e.t-L, e.y+L, e.z+L, e.t+L);
bit.upd(e.y, e.z, e.t, 1);
} else {
bit.upd(e.y, e.z, e.t, -1);
}
}
cout << Ans << endl;
}
};
namespace TC2YAME {
const static int MX = 131072;
struct SEGNOD {
SEGNOD() : l(NULL), r(NULL), dt(0) {}
SEGNOD *l, *r;
int dt;
void upd(int s, int e, int x) {
dt++; if(s == e) return;
int m = (s+e)/2;
if(x <= m) {
if(NULL == l) l = new SEGNOD();
l -> upd(s, m, x);
} else {
if(NULL == r) r = new SEGNOD();
r -> upd(m+1, e, x);
}
}
int get(int s, int e, int p, int q) {
if(q < p || e < p || q < s) return 0;
if(p <= s && e <= q) return dt;
int m = (s+e)/2;
return (NULL == l ? 0 : l -> get(s, m, p, q)) + (NULL == r ? 0 : r -> get(m+1, e, p, q));
}
};
struct SEG {
SEGNOD nod[MX*2];
void upd(int x, int y) {
for(x += MX; x; x /= 2)
nod[x].upd(1, 75000*2, y);
}
int get(int s, int e, int p, int q) {
int r = 0; for(s += MX, e += MX; s <= e; s /= 2, e /= 2) {
if(s&1) r += nod[s++].get(1, 75000*2, p, q);
if(~e&1) r += nod[e--].get(1, 75000*2, p, q);
} return r;
}
};
SEG segxy, segyx;
int X[100005], Y[100005];
ll Ans;
int N, L, M;
void init(int _N, int _L, int _M) {
N = _N; L = _L; M = _M;
Ans = 0;
fill(X, X+100005, 0);
fill(Y, Y+100005, 0);
}
void run() {
{
vector<pii> V;
for(int i = 1, x, y; i <= N; i++) {
cin >> x >> y;
V.eb(x, y);
}
sorv(V);
for(int i = 1; i <= N; i++)
tie(X[i], Y[i]) = V[i-1];
}
for(int i = 1, x, y; i <= N; i++) {
x = X[i]; y = Y[i];
Ans += segxy.get(1, y, x+y-L, 75000*2);
Ans += segyx.get(y+1, 75000, 1, y-x+L+75000);
segxy.upd(y, x+y);
segyx.upd(y, y-x+75000);
}
cout << Ans << endl;
}
};
int K, N, L, M;
int main() {
//freopen("input.txt", "r", stdin);
ios::sync_with_stdio(false);
cin >> K >> N >> L >> M;
if(1 == K) {
TC1 :: init(N, L, M);
TC1 :: run();
}
else if(2 == K) {
if(80000 <= N) {
TC2 :: init(N, L, M);
TC2 :: run();
} else {
TC2YAME :: init(N, L, M);
TC2YAME :: run();
}
}
else {
TC3 :: init(N, L, M);
TC3 :: run();
}
return 0;
}
Compilation message
pairs.cpp: In member function 'int TC3::BIT::get(int, int, int)':
pairs.cpp:137:21: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int k = z; k; k -= rb(k))
^~~
pairs.cpp:139:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
return r;
^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
14712 KB |
Output is correct |
2 |
Correct |
12 ms |
14712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
14764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
15148 KB |
Output is correct |
2 |
Correct |
26 ms |
15180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
15180 KB |
Output is correct |
2 |
Correct |
33 ms |
15184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
15184 KB |
Output is correct |
2 |
Correct |
34 ms |
15184 KB |
Output is correct |
3 |
Correct |
32 ms |
15360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
31364 KB |
Output is correct |
2 |
Correct |
43 ms |
31368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
65 ms |
38804 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
39580 KB |
Output is correct |
2 |
Correct |
87 ms |
39580 KB |
Output is correct |
3 |
Correct |
84 ms |
39604 KB |
Output is correct |
4 |
Correct |
90 ms |
39604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
39604 KB |
Output is correct |
2 |
Correct |
80 ms |
39604 KB |
Output is correct |
3 |
Correct |
93 ms |
39604 KB |
Output is correct |
4 |
Correct |
91 ms |
39604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
45660 KB |
Output is correct |
2 |
Correct |
20 ms |
45660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
45660 KB |
Output is correct |
2 |
Correct |
145 ms |
45660 KB |
Output is correct |
3 |
Correct |
174 ms |
45660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
57460 KB |
Output is correct |
2 |
Correct |
241 ms |
57520 KB |
Output is correct |
3 |
Correct |
189 ms |
57520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
65188 KB |
Output is correct |
2 |
Correct |
294 ms |
65188 KB |
Output is correct |
3 |
Correct |
207 ms |
65188 KB |
Output is correct |