# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54544 |
2018-07-04T04:17:29 Z |
윤교준(#1492) |
Pairs (IOI07_pairs) |
C++11 |
|
2339 ms |
154624 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 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;
fill(A, A+100005, 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 {
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) {
TC2 :: init(N, L, M);
TC2 :: run();
}
else;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
13048 KB |
Output is correct |
2 |
Correct |
12 ms |
13160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
13160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
13160 KB |
Output is correct |
2 |
Correct |
26 ms |
13160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
13160 KB |
Output is correct |
2 |
Correct |
31 ms |
13288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
13288 KB |
Output is correct |
2 |
Correct |
32 ms |
13288 KB |
Output is correct |
3 |
Correct |
31 ms |
13288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
29416 KB |
Output is correct |
2 |
Correct |
42 ms |
29416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
344 ms |
29416 KB |
Output is correct |
2 |
Correct |
293 ms |
29416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1618 ms |
113988 KB |
Output is correct |
2 |
Correct |
1979 ms |
114036 KB |
Output is correct |
3 |
Correct |
717 ms |
114036 KB |
Output is correct |
4 |
Correct |
1166 ms |
114036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2339 ms |
154624 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
154624 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
154624 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
154624 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
154624 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |