# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
144186 | SamAnd | Segway (COI19_segway) | C++17 | 228 ms | 13436 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 20004, M = 305;
struct ban
{
int x, y, z;
};
struct ban1
{
int i, x, q;
ban1(){}
ban1(int i, int x, int q)
{
this->i = i;
this->x = x;
this->q = q;
}
};
int n;
ban a[N];
int m;
bool c[M];
queue<ban1> q[M * 50];
int t[M];
void ubd(int x, int y)
{
++x;
while (x < M)
{
t[x] += y;
x += (x & (-x));
}
}
int qry(int l, int r)
{
int ans = 0;
++r;
while (r > 0)
{
ans += t[r];
r -= (r & (-r));
}
while (l > 0)
{
ans -= t[l];
l -= (l & (-l));
}
return ans;
}
int qq[M];
int ans[N];
int main()
{
//freopen("input.txt", "r", stdin);
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
{
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
}
scanf("%d", &m);
for (int i = 0; i < m; ++i)
{
int x;
scanf("%d", &x);
c[x] = true;
}
for (int i = 1; i <= n; ++i)
{
q[0].push(ban1(i, 0, 0));
ubd(0, 1);
}
for (int i = 0; i < M * 50; ++i)
{
memset(qq, 0, sizeof qq);
while (!q[i].empty())
{
ban1 t = q[i].front();
q[i].pop();
if (t.x == 300)
{
ans[t.i] = i;
continue;
}
ubd(t.x, -1);
if (!t.q && c[t.x])
{
t.q = ((qry(t.x + 1, 300) - qq[t.x]) % 20);
}
int d;
if (t.q)
{
d = i + 1;
}
else
{
if (t.x >= 200)
d = i + a[t.i].z;
else if (t.x >= 100)
d = i + a[t.i].y;
else
d = i + a[t.i].x;
}
qq[t.x]++;
if (t.q)
{
--t.q;
++t.x;
}
else
{
++t.x;
}
q[d].push(t);
ubd(t.x, 1);
}
}
for (int i = 1; i <= n; ++i)
printf("%d\n", ans[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |