QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47391 | #4495. Shinobu loves trip | miaomiaozi | AC ✓ | 1224ms | 14520kb | C++ | 1.9kb | 2022-09-08 21:41:04 | 2022-09-08 21:41:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672346917
#ifndef LOCAL
#define LOG(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long LL;
typedef pair <int, int> PII;
constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-8;
const double PI = acos(-1);
int multi_cases = 1;
constexpr int N = 200000;
void A_SOUL_AvA () {
int a, n, q, P;
cin >> P >> a >> n >> q;
vector <LL> fact(N + 5);
fact[0] = 1;
auto power = [&](int a, int b) -> int {
LL res = 1;
for ( ; b; b >>= 1, a = 1LL * a * a % P) {
if (b & 1) {
res = res * a % P;
}
}
return res;
};
map <int, int> w;
w[1] = 0;
for (int i = 1; i <= N; i++) {
fact[i] = fact[i - 1] * a % P;
if (!w.count(fact[i])) {
w[fact[i]] = i;
}
}
vector <pair<int, int>> plan(n);
for (int i = 0; i < n; i++) {
auto &[u, v] = plan[i];
cin >> u >> v;
if (u > 0) {
u = power(u, P - 2);
}
}
while (q--) {
int x;
cin >> x;
int ans = 0;
for (auto &[st, day] : plan) {
if (st == 0) {
ans += (x == 0);
} else {
// st > 0
int need = 1LL * x * st % P;
if (w.count(need)) {
int to = w[need];
ans += (to <= day);
}
}
}
cout << ans << "\n";
}
}
int main () {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(12);
int T = 1;
for (multi_cases && cin >> T; T; T--) {
A_SOUL_AvA ();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1224ms
memory: 14520kb
input:
5 999999937 4628 1000 1000 162585517 24584 407438671 108585 46973547 132178 142179754 23710 198067620 130706 829852550 190969 676555968 2127 717426372 80994 332054419 1078 471194333 66473 105470508 154839 939339406 89663 73289403 90982 529133484 198011 526081635 28219 405427868 174742 120011816 6408...
output:
167 166 168 168 174 169 2 167 169 22 153 169 150 163 7 152 149 166 166 176 63 178 125 170 94 167 155 173 56 147 163 169 167 183 78 165 179 173 182 170 166 150 152 166 169 169 169 173 162 52 180 182 170 163 173 173 175 150 171 166 170 148 170 166 63 168 172 151 150 72 129 14 61 167 167 169 174 133 17...
result:
ok 5000 lines