QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#488044 | #9155. 集合 | lfxxx | 100 ✓ | 195ms | 36260kb | C++14 | 1.9kb | 2024-07-23 15:37:14 | 2024-07-23 15:37:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
bool be;
random_device gen;
mt19937_64 rd(gen());
constexpr int N = 6e5 + 5, B1 = 911, B2 = 13331;
int n, m, Q, a[N], b[N], pos[N], prea[N], preb[N], nxta[N], nxtb[N], ans[N];
ull ha[N], hb[N], rk[N], sa, sb;
inline ull sqr(ull x)
{
return x * x * x * x + x * x * x + x * x + x + (x ^ 12431786);
}
inline int Pos(int x)
{
return (x + 2) / 3;
}
inline void ins(int x)
{
sa = sa - sqr(ha[a[x]]) + sqr(ha[a[x]] + rk[Pos(x)]);
sb = sb - sqr(hb[b[x]]) + sqr(hb[b[x]] + rk[Pos(x)]);
ha[a[x]] += rk[Pos(x)], hb[b[x]] += rk[Pos(x)];
}
inline void eras(int x)
{
sa = sa - sqr(ha[a[x]]) + sqr(ha[a[x]] - rk[Pos(x)]);
sb = sb - sqr(hb[b[x]]) + sqr(hb[b[x]] - rk[Pos(x)]);
ha[a[x]] -= rk[Pos(x)], hb[b[x]] -= rk[Pos(x)];
}
bool en;
int main()
{
cerr << (&be - &en) / 1024.0 / 1024 << " MB\n--------------------------------" << endl;
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> Q;
for (int i = 1; i <= 3 * n; ++i) {
rk[i] = rd();
}
for (int i = 1; i <= 3 * n; ++i) {
cin >> a[i];
prea[i] = pos[a[i]];
nxta[pos[a[i]]] = i;
pos[a[i]] = i;
}
for (int i = 1; i <= m; ++i) pos[i] = 0;
for (int i = 1; i <= 3 * n; ++i) {
cin >> b[i];
preb[i] = pos[b[i]];
nxtb[pos[b[i]]] = i;
pos[b[i]] = i;
}
for (int l = 1, r = 0; l <= n; ++l) {
while (r < n) {
ins(r * 3 + 1);
ins(r * 3 + 2);
ins(r * 3 + 3);
// cerr << l << ' ' << r + 1 << ' ' << sa << ' ' << sb << '\n';
if (sa != sb) {
eras(r * 3 + 1);
eras(r * 3 + 2);
eras(r * 3 + 3);
break;
}
++r;
}
ans[l] = r;
eras(l * 3 - 2);
eras(l * 3 - 1);
eras(l * 3);
}
while (Q--) {
int l, r;
cin >> l >> r;
cout << (ans[l] >= r ? "Yes\n" : "No\n");
}
return 0;
}
详细
Pretests
Pretest #1:
score: 5
Accepted
time: 0ms
memory: 18228kb
Pretest #2:
score: 5
Accepted
time: 0ms
memory: 18424kb
Pretest #3:
score: 5
Accepted
time: 0ms
memory: 18196kb
Pretest #4:
score: 5
Accepted
time: 0ms
memory: 18360kb
Pretest #5:
score: 5
Accepted
time: 2ms
memory: 18200kb
Pretest #6:
score: 5
Accepted
time: 2ms
memory: 18140kb
Pretest #7:
score: 5
Accepted
time: 0ms
memory: 18148kb
Pretest #8:
score: 5
Accepted
time: 0ms
memory: 18328kb
Pretest #9:
score: 5
Accepted
time: 20ms
memory: 18204kb
Pretest #10:
score: 5
Accepted
time: 21ms
memory: 18340kb
Pretest #11:
score: 5
Accepted
time: 72ms
memory: 29676kb
Pretest #12:
score: 5
Accepted
time: 82ms
memory: 29076kb
Pretest #13:
score: 5
Accepted
time: 0ms
memory: 18404kb
Pretest #14:
score: 5
Accepted
time: 3ms
memory: 18360kb
Pretest #15:
score: 5
Accepted
time: 106ms
memory: 18244kb
Pretest #16:
score: 5
Accepted
time: 100ms
memory: 20412kb
Pretest #17:
score: 5
Accepted
time: 4ms
memory: 20724kb
Pretest #18:
score: 5
Accepted
time: 10ms
memory: 21884kb
Pretest #19:
score: 5
Accepted
time: 175ms
memory: 29612kb
Pretest #20:
score: 5
Accepted
time: 191ms
memory: 35764kb
Final Tests
Test #1:
score: 5
Accepted
time: 0ms
memory: 18424kb
Test #2:
score: 5
Accepted
time: 0ms
memory: 18212kb
Test #3:
score: 5
Accepted
time: 0ms
memory: 18200kb
Test #4:
score: 5
Accepted
time: 0ms
memory: 18192kb
Test #5:
score: 5
Accepted
time: 2ms
memory: 18200kb
Test #6:
score: 5
Accepted
time: 2ms
memory: 18364kb
Test #7:
score: 5
Accepted
time: 0ms
memory: 18204kb
Test #8:
score: 5
Accepted
time: 0ms
memory: 18364kb
Test #9:
score: 5
Accepted
time: 16ms
memory: 18200kb
Test #10:
score: 5
Accepted
time: 21ms
memory: 18156kb
Test #11:
score: 5
Accepted
time: 64ms
memory: 26424kb
Test #12:
score: 5
Accepted
time: 67ms
memory: 29272kb
Test #13:
score: 5
Accepted
time: 0ms
memory: 18192kb
Test #14:
score: 5
Accepted
time: 3ms
memory: 18456kb
Test #15:
score: 5
Accepted
time: 97ms
memory: 18472kb
Test #16:
score: 5
Accepted
time: 103ms
memory: 18524kb
Test #17:
score: 5
Accepted
time: 3ms
memory: 22772kb
Test #18:
score: 5
Accepted
time: 11ms
memory: 20064kb
Test #19:
score: 5
Accepted
time: 179ms
memory: 29344kb
Test #20:
score: 5
Accepted
time: 195ms
memory: 36260kb
Extra Test:
score: 0
Extra Test Passed