QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673593 | #7949. K-Lottery | ucup-team3519 | TL | 1344ms | 286776kb | C++17 | 6.7kb | 2024-10-25 00:58:00 | 2024-10-25 00:58:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef __int128_t LLL;
typedef long long LL;
#define V vector
#define pb push_back
typedef unsigned long long ULL;
typedef long long LL;
#define lb lower_bound
#define all0(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()
#define fi first
#define se second
typedef pair<LL, LL> pl;
const int N = 2e6 + 10;
const LL mod1 = 998244353;
const LL mod2 = 1e9 + 7;
const LL base1 = 23333;
const LL base2 = 114514;
LL MOD(LL x, LL mod) {
if(x >= mod) x -= mod;
if(x < 0) x += mod;
return x;
}
pl operator+(pl a, pl b) {
return {MOD(a.fi + b.fi, mod1), MOD(a.se + b.se, mod2)};
}
pl operator-(pl a, pl b) {
return {MOD(a.fi - b.fi, mod1), MOD(a.se - b.se, mod2)};
}
pl operator*(pl a, pl b) {
return {a.fi * b.fi % mod1, a.se * b.se % mod2};
}
pl operator*(pl a, int b) {
return {a.fi * b % mod1, a.se * b % mod2};
}
LL qpow(LL x, LL k, LL mod) {
LL ans = 1;
while(k) {
if(k & 1) ans = ans * x % mod;
k /= 2;
x = x * x % mod;
}
return ans;
}
struct Node {
pl sum_val, mul_pbs;
Node() {
sum_val = {0, 0}, mul_pbs = {1, 1};
}
} seg[N << 2];
void pull_up(int node) {
seg[node].sum_val = seg[node << 1].sum_val + seg[node << 1 | 1].sum_val;
}
void apply(int node, pl mul_pbs) {
seg[node].sum_val = seg[node].sum_val * mul_pbs;
seg[node].mul_pbs = mul_pbs * seg[node].mul_pbs;
}
void push_down(int node) {
if (seg[node].mul_pbs != pl{1, 1}) {
pl &tag = seg[node].mul_pbs;
apply(node << 1, tag);
apply(node << 1 | 1, tag);
tag = {1, 1};
}
}
void modify(int node, int L, int R, int pos, pl val) {
if (L == R) {
seg[node].sum_val = val;
return;
}
push_down(node);
int mid = (L + R) / 2;
if (pos <= mid) modify(node << 1, L, mid, pos, val);
else modify(node << 1 | 1, mid + 1, R, pos, val);
pull_up(node);
}
// void seg_show(int node, int L, int R, int pos) {
// if (L == R) {
// cout << "sum _val : " << seg[node].sum_val << endl;
// cout << "tag : " << seg[node].mul_pbs << endl;
// // cout << "fine : " << seg[node].fine << endl;
// return;
// }
// push_down(node);
// int mid = (L + R) / 2;
// if (pos <= mid) seg_show(node << 1, L, mid, pos);
// else seg_show(node << 1 | 1, mid + 1, R, pos);
// pull_up(node);
// }
void range_apply(int node, int L, int R, int l, int r, pl tag) {
if (l <= L && R <= r) {
apply(node, tag);
return;
}
push_down(node);
int mid = (L + R) / 2;
if (l <= mid) range_apply(node << 1, L, mid, l, r, tag);
if (r > mid) range_apply(node << 1 | 1, mid + 1, R, l, r, tag);
pull_up(node);
}
namespace fast {
char B[1 << 18], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 18, stdin), S == T) ? 0 : *S++)
int read() {
int ret = 0;
char c;
while(c = getc(), c < '0' || c > '9');
for(; c >= '0' && c <= '9'; c = getc()) ret = ret * 10 + c - '0';
return ret;
}
}
using fast::read;
mt19937 mrand(chrono::steady_clock().now().time_since_epoch().count());
struct BIT {
LL fenT[N];
void add(int x, LL d) {
assert(x > 0);
while(x < N) {
fenT[x] = fenT[x] + d;
x += x & (-x);
}
}
LL query(int x) {
LL ans = 0;
while(x >= 1) {
ans = ans + fenT[x];
x -= x & (-x);
}
return ans;
}
LL query(int l, int r) {
return query(r) - query(l - 1);
}
}bit;
int main() {
// ios::sync_with_stdio(0), cin.tie(0);
// int k = 1000, m = 1000;
// int n = 1e6;
// int k, m, n; cin >> k >> m >> n;
int k, m, n; k = read(), m = read(), n = read();
pl inv_base = {qpow(base1, mod1 - 2, mod1), qpow(base2, mod2 - 2, mod2)};
V<pl> hs(m + 1);
V<V<int>> tab(m + 1);
for(int i = 1; i <= m; i++) {
V<int> a(k + 1);
for(int j = 1; j <= k; j++) a[j] = read();
tab[i] = a;
V<int> pos(k + 1);
for(int j = 1; j <= k; j++) pos[a[j]] = j;
pl cur = {0, 0};
for(int j = 1; j <= k; j++) {
cur = cur * pl{base1, base2} + pl{pos[j], pos[j]};
}
hs[i] = cur;
}
map<pl, int> mp;
for(int i = 1; i <= m; i++) mp[hs[i]] = i;
V<int> sheet(n + 1);
for(int i = 1; i <= n; i++) sheet[i] = read();
V<int> ord(n + 1);
iota(all1(ord), 1);
sort(all1(ord), [&](int x, int y) {
return sheet[x] < sheet[y];
});
for(int i = 1; i <= n; i++) sheet[ord[i]] = i;
int tot = 1e6;
V<pl> powerbase(tot + 1);
powerbase[0] = {1, 1};
for(int i = 1; i <= tot; i++) powerbase[i] = powerbase[i - 1] * pl{base1, base2};
// auto show = [&](int n) -> void {
// for(int i = 1; i <= n; i++) seg_show(1, 1, tot, i);
// };
// show(10);
pl basic = {};
for(int i = 1; i <= k; i++) {
basic = pl{base1, base2} * basic + pl{1, 1};
}
// for(int i = 1; i <= 3; i++) cout << powerbase[i] << " ";
// cout << endl;
auto add = [&](int x, int cur) -> void {
if(x != 1) range_apply(1, 1, tot, 1, x - 1, {base1, base2});
modify(1, 1, tot, x, pl{cur, cur} * powerbase[bit.query(x + 1, N - 1)]);
// cout << "query : " << bit.query(x + 1, N - 1) << endl;
bit.add(x, 1);
};
auto del = [&](int x) -> void {
if(x != 1) range_apply(1, 1, tot, 1, x - 1, inv_base);
modify(1, 1, tot, x, {});
bit.add(x, -1);
};
auto get = [&](int cur) -> pl {
return seg[1].sum_val - (basic * (cur - k));
};
// for(int i = 1; i <= n; i++) cout << sheet[i] << " ";
// cout << endl;
// V<LL> hav;
// for(int i = 1; i <= m; i++) hav.pb(hs[i]);
// sort(all0(hav));
// auto got = [&](LL x) {
// auto it = lb(all0(hav), x);
// if(*it == x) return 1;
// return 0;
// };
for(int i = 1; i <= n; i++) {
// cout << "I : " << i << endl;
if(i - k >= 1) del(sheet[i - k]);
add(sheet[i], i);
//i -> k
// cout << "i : " << i << endl;
// show(10);
if(i >= k && mp.count(get(i))) {
int id = mp[get(i)];
for(int i = 1; i <= k; i++) cout << tab[id][i] << " ";
cout << endl;
// cout << (double)clock() / CLOCKS_PER_SEC << endl;
return 0;
}
// cout << get() << endl;
}
cout << 0 << endl;
// cout << (double)clock() / CLOCKS_PER_SEC << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 23ms
memory: 269532kb
input:
3 2 10 1 2 3 1 3 2 20 35 10 7 99 53 72 33 88 16
output:
1 3 2
result:
ok single line: '1 3 2 '
Test #2:
score: 0
Accepted
time: 16ms
memory: 269952kb
input:
4 5 10 1 2 3 4 1 2 4 3 3 4 1 2 4 1 2 3 4 2 3 1 19 31 9 1 89 48 63 30 78 12
output:
4 2 3 1
result:
ok single line: '4 2 3 1 '
Test #3:
score: 0
Accepted
time: 20ms
memory: 269492kb
input:
3 3 7 1 3 2 2 3 1 2 1 3 11 22 33 44 55 66 77
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1344ms
memory: 286776kb
input:
10000 10 1000000 1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5...
output:
1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5037 38 5038 39 50...
result:
ok single line: '1 5001 2 5002 3 5003 4 5004 5 ...4998 9998 4999 9999 5000 10000 '
Test #5:
score: -100
Time Limit Exceeded
input:
10000 10 1000000 7171 4541 8189 3253 6694 2078 7384 1786 7847 5040 953 4126 4806 3532 7875 8531 3543 2706 8565 1509 2092 4125 6110 5251 6314 4574 6726 8900 9328 8639 3990 5234 9012 5023 3289 2825 8038 3593 2249 337 6252 3831 7967 3839 2815 540 3754 1009 8772 2939 2845 5067 6587 2615 375 7252 9940 18...