# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54555 |
2018-07-04T05:16:21 Z |
윤교준(#1492) |
Pairs (IOI07_pairs) |
C++11 |
|
314 ms |
35632 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*2;
struct SEG {
SEG() { init(); }
int d[MX*2];
void init() { fill(d, d+MX*2, 0); }
void upd(int x, int r) {
for(x += MX; x; x /= 2)
d[x] += r;
}
int get(int s, int e) {
int r = 0;
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++)
Y[i] += 75000;
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(max(1, e.y - L), min(75000*2, 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;
}
};
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) {
TC2 :: init(N, L, M);
TC2 :: 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:138:21: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int k = z; k; k -= rb(k))
^~~
pairs.cpp:140: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 |
5 ms |
4476 KB |
Output is correct |
2 |
Correct |
5 ms |
4588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
4964 KB |
Output is correct |
2 |
Correct |
20 ms |
5008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
5064 KB |
Output is correct |
2 |
Correct |
29 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
5064 KB |
Output is correct |
2 |
Correct |
26 ms |
5064 KB |
Output is correct |
3 |
Correct |
26 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5064 KB |
Output is correct |
2 |
Correct |
6 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
10076 KB |
Output is correct |
2 |
Correct |
55 ms |
10080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
10080 KB |
Output is correct |
2 |
Correct |
72 ms |
10080 KB |
Output is correct |
3 |
Correct |
69 ms |
10080 KB |
Output is correct |
4 |
Correct |
79 ms |
10096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
10096 KB |
Output is correct |
2 |
Correct |
74 ms |
10128 KB |
Output is correct |
3 |
Correct |
73 ms |
10128 KB |
Output is correct |
4 |
Correct |
65 ms |
10128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
16076 KB |
Output is correct |
2 |
Correct |
14 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
151 ms |
16076 KB |
Output is correct |
2 |
Correct |
145 ms |
16076 KB |
Output is correct |
3 |
Correct |
171 ms |
16076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
28136 KB |
Output is correct |
2 |
Correct |
243 ms |
28136 KB |
Output is correct |
3 |
Correct |
163 ms |
28136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
35524 KB |
Output is correct |
2 |
Correct |
262 ms |
35632 KB |
Output is correct |
3 |
Correct |
164 ms |
35632 KB |
Output is correct |