Submission #48675


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef enum {
//rotate
F = 0,
//direction
U = 0,
R = 1,
D = 2,
L = 3
} Dir;
struct st {
ll x, y;
char d;
char ang;
};
struct SegmentTree {
vector<st> dat;
int size;
st merge(st l, st r)
{
st res;
ll tmp;
//rotate
switch(l.d) {
//case 'U':
case D:
r.x *= -1;
r.y *= -1;
break;
case R:
tmp = r.x;
r.x = r.y;
r.y = -tmp;
break;
case L:
tmp = r.x;
r.x = -r.y;
r.y = tmp;
}
//vector
switch(l.ang) {
case F:
res.x = l.x + r.x;
res.y = l.y + r.y;
break;
case R:
res.x = l.x + r.y;
res.y = l.y - r.x;
break;
case L:
res.x = l.x - r.y;
res.y = l.y + r.x;
break;
}
//direction
res.d = (l.d + l.ang + r.d) % 4;
res.ang = r.ang;
return res;
}
void init(int n)
{
size = 1;
while (size < n) {
size *= 2;
}
dat.resize(2 * size, (st){0, 0, 0, 0});
}
void update(int key, st a)
{
key += size - 1;
dat[key] = a;
while (key > 0) {
key = (key - 1) / 2;
dat[key] = merge(dat[key * 2 + 1], dat[key * 2 + 2]);
}
}
st top(void)
{
return dat[0];
}
};
SegmentTree seg;
int main()
{
ll n, q;
ll sx, sy;
ll t;
char d;
cin >> n >> q;
cin >> sx >> sy;
seg.init(n + 1);
seg.update(0, (st){sx, sy, U, F});
for (int i = 1; i <= n; i++) {
seg.update(i, (st){0, 1, U, F});
}
//cout << seg.top().x << ' ' << seg.top().y << endl;
for (int i = 0; i < q; i++) {
cin >> t >> d;
if (d == 'L') {
seg.update(t, (st){0, 1, U, L});
}
else {
seg.update(t, (st){0, 1, U, R});
}
cout << seg.top().x << ' ' << seg.top().y << endl;
}
return 0;
}

ステータス

項目 データ
問題 1126 - 創世の種
ユーザー名 ei1710
投稿日時 2019-04-24 16:25:16
言語 C++14
状態 Accepted
得点 100
ソースコード長 1948 Byte
最大実行時間 273 ms
最大メモリ使用量 11048 KB

セット

セット 得点 Cases
1 ALL 100 / 100 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in_1.txt AC 27 ms 604 KB
1
in_2.txt AC 258 ms 9248 KB
1
in_3.txt AC 18 ms 3204 KB
1
in_4.txt AC 32 ms 3300 KB
1
in_5.txt AC 273 ms 10260 KB
1
in_6.txt AC 35 ms 4080 KB
1
in_7.txt AC 18 ms 4424 KB
1
in_8.txt AC 265 ms 11048 KB
1
in_9.txt AC 32 ms 11016 KB
1
in_10.txt AC 214 ms 2628 KB
1