# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
799892 |
2023-08-01T07:44:49 Z |
이동현(#10084) |
Harvest (JOI20_harvest) |
C++17 |
|
5000 ms |
6208 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, l, c;
cin >> n >> m >> l >> c;
vector<int> a(n), b(m);
for(int i = 0; i < n; ++i){
cin >> a[i];
}
for(int i = 0; i < m; ++i){
cin >> b[i];
}
auto god = [&](int x, int y){
return c + (y - c % l - x + l * 2) % l;
};
vector<vector<int>> mine(n);
int p = 0;
for(int i = 0; i < n; ++i){
while(p < m && a[i] > b[p]) ++p;
int r = p - 1;
while(r + 1 < m && (i == n - 1 || b[r + 1] < a[i + 1])){
++r;
mine[i].push_back((b[r] - a[i] + l) % l);
}
p = r;
}
for(int i = 0; i < m && b[i] < a[0]; ++i){
mine[n - 1].push_back(i);
}
vector<int> got(n);
vector<vector<int>> way(n);
for(int i = 0; i < n; ++i){
int pos = (a[i] - c % l + l) % l;
int p = lower_bound(a.begin(), a.end(), pos + 1) - a.begin();
--p;
if(p < 0) p = n - 1;
got[i] = p;
way[p].push_back(i);
}
int q;
cin >> q;
vector<int> ans(q);
vector<vector<array<int, 2>>> que(n);
for(int i = 0; i < q; ++i){
int x, y;
cin >> x >> y;
--x;
que[x].push_back({y, i});
}
vector<int> cyclen(n, -1);
vector<int> chk(n), cdist(n);
int cn = 0;
auto checkcycle = [&](auto&&self, int x)->void{
if(chk[x]) return;
chk[x] = cn;
if(chk[got[x]] == chk[x]){
int val = cdist[x] - cdist[got[x]] + god(a[got[x]], a[x]);
// cout << x << ' ' << dist << ' ' << god(a[x], a[x]) << endl;
while(cyclen[x] == -1){
cyclen[x] = val;
x = got[x];
}
return;
}
cdist[got[x]] = cdist[x] + god(a[got[x]], a[x]);
self(self, got[x]);
};
for(int i = 0; i < n; ++i){
++cn;
checkcycle(checkcycle, i);
}
for(int i = 0; i < n; ++i){
vector<int> chk(n);
// cout << got[i] << ' ' << cyclen[i] << endl;
auto sol = [&](auto&&self, int x, int dist)->void{
if(chk[x]) return;
chk[x] = 1;
for(auto&[t, anspos]:que[i]){
// int p = lower_bound(mine[x].begin(), mine[x].end(), t - dist + 1) - mine[x].begin();
// if(cyclen[x] != -1){
// }
for(auto&j:mine[x]){
if(j + dist > t) continue;
// cout << i << ' ' << x << ' ' << dist << ' ' << j << ' ' << anspos << endl;
ans[anspos] += 1 + (cyclen[i] != -1 ? (t - (j + dist)) / cyclen[i] : 0);
}
}
for(auto&nxt:way[x]){
self(self, nxt, dist + god(a[x], a[nxt]));
}
};
sol(sol, i, 0);
}
for(int i = 0; i < q; ++i){
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
80 ms |
896 KB |
Output is correct |
4 |
Correct |
11 ms |
852 KB |
Output is correct |
5 |
Correct |
66 ms |
1128 KB |
Output is correct |
6 |
Correct |
64 ms |
1152 KB |
Output is correct |
7 |
Correct |
66 ms |
1140 KB |
Output is correct |
8 |
Correct |
3 ms |
976 KB |
Output is correct |
9 |
Correct |
3 ms |
980 KB |
Output is correct |
10 |
Correct |
3 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
980 KB |
Output is correct |
12 |
Correct |
131 ms |
1156 KB |
Output is correct |
13 |
Correct |
206 ms |
1200 KB |
Output is correct |
14 |
Correct |
86 ms |
1124 KB |
Output is correct |
15 |
Correct |
33 ms |
1108 KB |
Output is correct |
16 |
Correct |
34 ms |
1108 KB |
Output is correct |
17 |
Correct |
35 ms |
1120 KB |
Output is correct |
18 |
Correct |
39 ms |
1060 KB |
Output is correct |
19 |
Incorrect |
39 ms |
1064 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5062 ms |
6208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
80 ms |
896 KB |
Output is correct |
4 |
Correct |
11 ms |
852 KB |
Output is correct |
5 |
Correct |
66 ms |
1128 KB |
Output is correct |
6 |
Correct |
64 ms |
1152 KB |
Output is correct |
7 |
Correct |
66 ms |
1140 KB |
Output is correct |
8 |
Correct |
3 ms |
976 KB |
Output is correct |
9 |
Correct |
3 ms |
980 KB |
Output is correct |
10 |
Correct |
3 ms |
980 KB |
Output is correct |
11 |
Correct |
3 ms |
980 KB |
Output is correct |
12 |
Correct |
131 ms |
1156 KB |
Output is correct |
13 |
Correct |
206 ms |
1200 KB |
Output is correct |
14 |
Correct |
86 ms |
1124 KB |
Output is correct |
15 |
Correct |
33 ms |
1108 KB |
Output is correct |
16 |
Correct |
34 ms |
1108 KB |
Output is correct |
17 |
Correct |
35 ms |
1120 KB |
Output is correct |
18 |
Correct |
39 ms |
1060 KB |
Output is correct |
19 |
Incorrect |
39 ms |
1064 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |