#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
struct Fenwick {
vector <int> aib;
int n;
inline void init(int _n) {
n = _n + 1;
aib.resize(n + 1);
}
inline void update(int pos, int val) {
pos++;
for(int i = pos; i <= n; i += lsb(i)) {
aib[i] += val;
}
}
inline int query(int pos) {
int ans = 0;
pos++;
for(int i = pos; i > 0; i -= lsb(i)) {
ans += aib[i];
}
return ans;
}
};
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, n, m;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
vector < vector <int> > speed(n + 1, vector <int>(3));
for(i = 1; i <= n; i++) {
for(j = 0; j < 3; j++) {
cin >> speed[i][j];
}
}
cin >> m;
vector <bool> vis(301);
while(m > 0) {
m--;
int x;
cin >> x;
vis[x] = 1;
}
Fenwick fen; fen.init(300);
vector < vector <int> > id(50 * 300 + 1);
vector <int> bonus(n + 1, 0), coord(n + 1, 0), new_coord(n + 1);
for(i = 1; i <= n; i++) {
id[0].push_back(i);
fen.update(0, 1);
}
vector <int> sol(n + 1);
for(i = 0; i <= 50 * 300; i++) {
int sz = id[i].size();
for(int j = 0; j < sz; j++) {
int it = id[i][j];
if(coord[it] == 300) {
continue;
}
if(bonus[it] == 0 && vis[coord[it]]) {
bonus[it] = (n - fen.query(coord[it])) % 20;
}
if(bonus[it] > 0) {
bonus[it]--;
id[i + 1].push_back(it);
}
else {
id[i + speed[it][coord[it] / 100]].push_back(it);
}
new_coord[it] = coord[it] + 1;
}
for(int j = 0; j < sz; j++) {
int it = id[i][j];
if(coord[it] == 300) {
sol[it] = i;
continue;
}
fen.update(coord[it], -1);
fen.update(new_coord[it], 1);
coord[it] = new_coord[it];
}
}
for(i = 1; i <= n; i++) {
cout << sol[i] << "\n";
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
15 ms |
2304 KB |
Output is correct |
4 |
Correct |
47 ms |
6148 KB |
Output is correct |
5 |
Correct |
317 ms |
34044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
896 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
4 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1152 KB |
Output is correct |
10 |
Correct |
7 ms |
1280 KB |
Output is correct |
11 |
Correct |
6 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
6 ms |
1152 KB |
Output is correct |
3 |
Correct |
15 ms |
2304 KB |
Output is correct |
4 |
Correct |
47 ms |
6148 KB |
Output is correct |
5 |
Correct |
317 ms |
34044 KB |
Output is correct |
6 |
Correct |
3 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
3 ms |
896 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
4 ms |
896 KB |
Output is correct |
13 |
Correct |
6 ms |
1024 KB |
Output is correct |
14 |
Correct |
6 ms |
1152 KB |
Output is correct |
15 |
Correct |
7 ms |
1280 KB |
Output is correct |
16 |
Correct |
6 ms |
1280 KB |
Output is correct |
17 |
Correct |
18 ms |
2552 KB |
Output is correct |
18 |
Correct |
23 ms |
4224 KB |
Output is correct |
19 |
Correct |
114 ms |
15348 KB |
Output is correct |
20 |
Correct |
163 ms |
20284 KB |
Output is correct |
21 |
Correct |
190 ms |
24056 KB |
Output is correct |
22 |
Correct |
309 ms |
29244 KB |
Output is correct |
23 |
Correct |
241 ms |
27000 KB |
Output is correct |