-
Notifications
You must be signed in to change notification settings - Fork 4
/
bugs.cpp
229 lines (175 loc) · 4.32 KB
/
bugs.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//IOI 2015 scales
- bool ok = false;
+ bool ok = true;
forn (q, 3)
if (!calc(b[sizes[q].second], bound - 1))
{
ok = false;
break;
}
//CF 315C
- dfs1(i);
+ forn (i, N)
+ if (!used[i])
+ dfs1(i);
//CF 315C
- forn (i, N)
+ for (int i: ord)
{
++COL;
if (!used[i])
dfs2(i);
}
//IOI 2015 horses
forn (i, n)
if (x[i] > 1)
- goodx.insert(x[i]);
+ goodx.insert(i);
//Petrsu summer camp 2015 day1 A
//Mergeable maps
- if (sz(a[i]) > sz(a[j]))
- swap(i, j);
+ bool swapped = false;
+ if (sz(a[i]) > sz(a[j]))
+ swap(i, j), swapped = true;
for (auto p: a[i].pref)
{
int x = p.first + a[i].bal;
ll cnt = p.second;
res += cnt * a[j].getsuf(x);
}
for (auto p: a[i].suf)
{
int x = p.first - a[i].bal;
ll cnt = p.second;
res += cnt * a[j].getpref(x);
}
- if (s[u] == '(')
- a[i].open();
- else
- a[i].close();
+ if (s[u] == '(')
+ a[swapped ? i : j].open();
+ else
+ a[swapped ? i : j].close();
//Petrsu summer camp 2015 day1 D
//Segment tree
+ fill(upd, upd + base * 2, 0);
//Petrsu summer camp 2015 day1 J
ld qwer = (x * cosl(phi) + y * sinl(phi)) / dist;
- ld dphi = acosl(min(1.0L, max(-1.0L, qwer)));
+ ld dphi = acosl(qwer);
//Petrsu summer camp 2015 day3 G
int getId(Node *t)
{
- int id = 0;
+ int id = cnt(t->l);
while (t->p)
{
if (t->p->r == t)
id += cnt(t->p->l) + 1;
t = t->p;
}
return id;
}
//Petrsu summer camp 2015 day4 C
forn (i, m)
{
scanf("%d", c + i + n);
s.emplace(c[i + n], i + n);
- ans[i] = -1;
+ ans[i + n] = -1;
}
//Petrsu summer camp 2015 day5 A
forn (i, n - 1)
{
int p;
cin >> p;
g[p].push_back(i + 1);
- ::p[i][0] = p;
+ ::p[i + 1][0] = p;
}
//Petrsu summer camp 2015 day5 A
- ans += min(R + 1, p.second) - max(L, p.first);
+ ans += max(0ll, min(R + 1, p.second) - max(L, p.first));
//Petrsu summer camp 2015 day2 J
cnt[u] = 1;
for (int v: g[u])
if (v != prev)
{
dfs(v, u, ch + 1);
+ cnt[u] += cnt[v];
}
//CF 327C
- if (res == INF)
+ if (res >= INF / 2)
res = -1;
//Opentrains 010026 F
struct E {
int v, c, w;
- } es[maxn];
+ } es[2 * maxn];
//Opentrains 010026 H
fill(mask, mask + n, 0);
- fill(init, mask + n, ll(-1));
+ fill(init, init + n, ll(-1));
//Opentrains 010026 H
- mask[v] |= (init[u] & mask[v]);
+ mask[v] |= (init[v] & mask[u]);
//Opentrains 001367 H
forn (i, n)
- forn (j, n)
+ forn (j, i)
//Opencup GP of Yekaterinburg
edge[e].f++;
- edge[e ^ 1].f++;
+ edge[e ^ 1].f--;
//Hackerrank testing
//Fenwick tree
- return get(xr, yr) + get(xl, yl) - get(xr, yl) - get(yr, xl);
+ return get(xr, yr) + get(xl, yl) - get(xr, yl) - get(xl, yr);
//Opencup GP of Siberia 4
+ cout.precision(10);
//Opencup GP of Siberia 3
- if (mask[u] | (ull(1) << (j - i)))
+ if (mask[u] & (ull(1) << (j - i)))
//Opencup GP of Siberia 6
return pos.x * cos(ang) + pos.y * -sin(ang)
- pos.x * sin(ang) + pos.x * cos(ang);
+ pos.x * sin(ang) + pos.y * cos(ang);
//MIPT Fall Day1 J
ld d[1 << maxn][maxn]; // some dynamic
...
int dist[maxn][maxn]; // distance matrix
...
forn (k, n)
forn (i, n)
forn (j, n)
- d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
+ dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
//Some task on PE
int add(int x, int y) {
x += y;
if (x >= mod) {
- x -= y;
+ x -= mod;
}
return x;
}
//CF 335C
//Before building a convex hull
sort(p, p + n, cmp);
+ n = unique(p, p + n) - p;
//CF WunderFund Round
t[v * 2] *= upd[v];
t[v * 2 + 1] *= upd[v];
+ upd[v * 2] *= upd[v];
+ upd[v * 2 + 1] *= upd[v];
upd[v] = 1;
//CF 8VC Cup
- int ans = max(a.back(), b.back());
+ int ans = 0;
+ if (!a.empty())
+ ans = max(ans, a.back());
+ if (!b.empty())
+ ans = max(ans, b.back());