# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
283880 |
2020-08-26T08:39:59 Z |
임성재(#5753) |
Ruka (COI15_ruka) |
C++17 |
|
2000 ms |
3324 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const ll inf = 1e9 + 7;
const int sz = 224;
int n, m, ans;
pii idx[sz * sz + 100];
int x[sz * sz + 100];
int y[sz * sz + 100];
int xh[sz+1];
int yh[sz+1];
int X[sz+1][sz+1], Y[sz+1][sz+1];
int xans[2][sz+1][sz], yans[2][sz+1][sz];
int A[sz+1];
void upd(int t) {
for(int i=0; i<sz-1; i++) {
xans[0][t][i] = min(X[t][i+1], X[t][i]);
xans[1][t][i] = max(X[t][i+1], X[t][i]);
yans[0][t][i] = min(Y[t][i+1], Y[t][i]);
yans[1][t][i] = max(Y[t][i+1], Y[t][i]);
}
sort(xans[0][t], xans[0][t] + sz - 1), sort(xans[1][t], xans[1][t] + sz - 1);
sort(yans[0][t], yans[0][t] + sz - 1), sort(yans[1][t], yans[1][t] + sz - 1);
}
int main() {
fast;
cin >> n;
for(int i=1; i <= sz * sz; i++) {
idx[i] = idx[i-1];
if(i % sz == 0) idx[i].fi++, idx[i].se = 0;
else idx[i].se++;
}
X[0][0] = Y[0][0] = 1;
for(int i=1; i <= sz * sz; i++) {
if(i <= n) cin >> x[i] >> y[i];
X[idx[i].fi][idx[i].se] = X[idx[i-1].fi][idx[i-1].se] + x[i];
Y[idx[i].fi][idx[i].se] = Y[idx[i-1].fi][idx[i-1].se] + y[i];
}
for(int i=0; i<sz; i++) {
upd(i);
A[i] += lower_bound(xans[0][i], xans[0][i] + sz - 1, xh[i]) - xans[0][i];
A[i] -= lower_bound(xans[1][i], xans[1][i] + sz - 1, xh[i]) - xans[1][i];
A[i] += lower_bound(yans[0][i], yans[0][i] + sz - 1, yh[i]) - yans[0][i];
A[i] -= lower_bound(yans[1][i], yans[1][i] + sz - 1, yh[i]) - yans[1][i];
ans += A[i];
}
cin >> m;
int cur = 1;
while(m--) {
char c;
cin >> c;
if(c == 'B') cur = max(1, cur - 1);
else if(c == 'F') cur = min(n, cur + 1);
else if(c == 'Q') {
int ret = 0;
for(int i = 0; i < sz; i++) {
if(i && (ll) (X[i][0] - xh[i]) * (X[i-1][sz-1] - xh[i-1]) < 0) ret++;
if(i && (ll) (Y[i][0] - yh[i]) * (Y[i-1][sz-1] - yh[i-1]) < 0) ret++;
}
cout << ret + ans << "\n";
}
else {
int dx = -x[cur];
int dy = -y[cur];
cin >> x[cur] >> y[cur];
dx += x[cur];
dy += y[cur];
for(int i = idx[cur].fi + 1; i < sz; i++) {
ans -= A[i];
xh[i] -= dx;
yh[i] -= dy;
A[i] = 0;
A[i] += lower_bound(xans[0][i], xans[0][i] + sz - 1, xh[i]) - xans[0][i];
A[i] -= lower_bound(xans[1][i], xans[1][i] + sz - 1, xh[i]) - xans[1][i];
A[i] += lower_bound(yans[0][i], yans[0][i] + sz - 1, yh[i]) - yans[0][i];
A[i] -= lower_bound(yans[1][i], yans[1][i] + sz - 1, yh[i]) - yans[1][i];
ans += A[i];
}
for(int i = idx[cur].se; i < sz; i++) {
X[idx[cur].fi][i] += dx;
Y[idx[cur].fi][i] += dy;
}
int i = idx[cur].fi;
upd(i);
ans -= A[i];
A[i] = 0;
A[i] += lower_bound(xans[0][i], xans[0][i] + sz - 1, xh[i]) - xans[0][i];
A[i] -= lower_bound(xans[1][i], xans[1][i] + sz - 1, xh[i]) - xans[1][i];
A[i] += lower_bound(yans[0][i], yans[0][i] + sz - 1, yh[i]) - yans[0][i];
A[i] -= lower_bound(yans[1][i], yans[1][i] + sz - 1, yh[i]) - yans[1][i];
ans += A[i];
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
1920 KB |
Output is correct |
3 |
Correct |
37 ms |
2040 KB |
Output is correct |
4 |
Correct |
24 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
1920 KB |
Output is correct |
3 |
Correct |
37 ms |
2040 KB |
Output is correct |
4 |
Correct |
24 ms |
2048 KB |
Output is correct |
5 |
Correct |
1139 ms |
2416 KB |
Output is correct |
6 |
Correct |
1593 ms |
2272 KB |
Output is correct |
7 |
Correct |
1774 ms |
2552 KB |
Output is correct |
8 |
Correct |
1925 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
1920 KB |
Output is correct |
3 |
Correct |
37 ms |
2040 KB |
Output is correct |
4 |
Correct |
24 ms |
2048 KB |
Output is correct |
5 |
Correct |
1139 ms |
2416 KB |
Output is correct |
6 |
Correct |
1593 ms |
2272 KB |
Output is correct |
7 |
Correct |
1774 ms |
2552 KB |
Output is correct |
8 |
Correct |
1925 ms |
2552 KB |
Output is correct |
9 |
Execution timed out |
2081 ms |
3324 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |