QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567058 | #9239. Hieroglyphs | ainta | 3 | 529ms | 135980kb | C++17 | 7.4kb | 2024-09-16 05:50:48 | 2024-09-16 05:50:48 |
Judging History
answer
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define rep(i,b) rng(i,0,b-1)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
#define per(i,b) gnr(i,b-1,0)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long ll;
using pii=pair<int,int>;
using vi=vc<int>;
using uint=unsigned;
using ull=unsigned long long;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using t3=tuple<int,int,int>;
ll rand_int(ll l, ll r) { //[l, r]
#ifdef LOCAL
static mt19937_64 gen;
#else
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif
return uniform_int_distribution<ll>(l, r)(gen);
}
template <uint MD> struct ModInt {
using M = ModInt;
const static M G;
uint v;
ModInt(ll _v = 0) { set_v(_v % MD + MD); }
M& set_v(uint _v) {
v = (_v < MD) ? _v : _v - MD;
return *this;
}
explicit operator bool() const { return v != 0; }
M operator-() const { return M() - *this; }
M operator+(const M& r) const { return M().set_v(v + r.v); }
M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
M operator/(const M& r) const { return *this * r.inv(); }
M& operator+=(const M& r) { return *this = *this + r; }
M& operator-=(const M& r) { return *this = *this - r; }
M& operator*=(const M& r) { return *this = *this * r; }
M& operator/=(const M& r) { return *this = *this / r; }
bool operator==(const M& r) const { return v == r.v; }
M pow(ll n) const {
M x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return pow(MD - 2); }
friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;
template<> const Mint Mint::G = Mint(3);
#include "hieroglyphs.h"
#define N_ 201000
int n, m;
int RA[N_], RB[N_], OrdA[N_], OrdB[N_], PP[N_];
vc<pii> D[N_];
int PR[N_];
const int SZ = (1<<18);
struct Tree{
set<pii>SetX[SZ+SZ];
set<pii>SetY[SZ+SZ];
void Put2(set<pii> &s, pii t){
s.insert(t);
auto it = s.find(t);
auto it2 = it; it2++;
if(it2!=s.end() && it2->se > t.se){
s.erase(it);
return;
}
while(it!=s.begin()){
it2 = it; it2--;
if(it2->se > t.se)break;
s.erase(it2);
}
}
void Put(int a, pii t){
a += SZ;
while(a){
Put2(SetX[a],t);
Put2(SetY[a],pii(t.se,t.fi));
a>>=1;
}
}
int Get2(set<pii> &s, int t){
auto it = s.lower_bound(pii(t,-1));
if(it == s.end())return -1;
return it->se;
}
int Get(int b, int e, int t, int ck){
b+=SZ,e+=SZ;
int r = -1;
while(b<=e){
if((b&1)){
if(ck==0)r = max(r, Get2(SetX[b], t));
else r = max(r, Get2(SetY[b], t));
}
if(!(e&1)){
if(ck==0)r = max(r, Get2(SetX[e], t));
else r = max(r, Get2(SetY[e], t));
}
b=(b+1)>>1,e=(e-1)>>1;
}
return r;
}
}IT;
vi GA[201000], GB[201000];
int RightA(int a, int x){
int pv = lower_bound(all(GA[a]),x)-GA[a].begin();
if(si(GA[a])==pv)return n+1;
return GA[a][pv];
}
int RightB(int a, int x){
int pv = lower_bound(all(GB[a]),x)-GB[a].begin();
if(si(GB[a])==pv)return m+1;
return GB[a][pv];
}
int LeftA(int a, int x){
int pv = lower_bound(all(GA[a]),x+1)-GA[a].begin();
if(!pv)return -1;
return GA[a][pv-1];
}
int LeftB(int a, int x){
int pv = lower_bound(all(GB[a]),x+1)-GB[a].begin();
if(!pv)return -1;
return GB[a][pv-1];
}
std::vector<int> ucs(std::vector<int> A, std::vector<int> B){
n=si(A);
m=si(B);
map<pii,array<int,3> >Map, Map2;
rep(i,n){
GA[A[i]].pb(i+1);
OrdA[i+1] = si(GA[A[i]]);
}
rep(i,m){
GB[B[i]].pb(i+1);
OrdB[i+1] = si(GB[B[i]]);
}
RA[n+1]=n+1;
RB[m+1]=m+1;
int sum=0;
rng(i,0,200000){
if(si(GA[i]) && si(GB[i])){
sum +=min(si(GA[i]),si(GB[i]));
if(si(GA[i]) <= si(GB[i])){
rep(j,si(GA[i])){
int a = GA[i][j];
RA[a]=a;
}
}
else{
rep(j,si(GB[i])){
int b = GB[i][j];
RB[b]=b;
}
}
}
}
vi imp = {-1};
if(!sum){
vi res;
return res;
}
gnr(i,n,1){
if(RA[i]!=i)RA[i]=RA[i+1];
}
gnr(i,m,1){
if(RB[i]!=i)RB[i]=RB[i+1];
}
Map[{0,0}] = {0,-1,-1};
int xx=-1,yy=-1;
int cc=0;
while(!Map.empty()){
cc++;
if(si(Map2) > 1e6){
return {-1};
}
auto [z,c] = *Map.begin();
Map2[z]=c;
auto [x,y] = z;
if(c[0]==sum){
xx = x,yy=y;
}
int t = RA[x+1];
if(t<=n){
int ch = A[t-1];
int pv = lower_bound(all(GB[ch]),y+1)-GB[ch].begin();
if(pv < si(GB[ch])){
if(si(GB[ch])-pv >= si(GA[ch]) - OrdA[t]){
pii tp = {t, GB[ch][pv]};
if(!Map.count(tp) || Map[tp][0]<=c[0]){
Map[tp]={c[0]+1, x,y};
}
}
}
}
t = RB[y+1];
if(t<=m){
int ch = B[t-1];
int pv = lower_bound(all(GA[ch]),x+1)-GA[ch].begin();
if(pv < si(GA[ch])){
if(si(GA[ch])-pv >= si(GB[ch]) - OrdB[t]){
pii tp = {GA[ch][pv], t};
if(!Map.count(tp) || Map[tp][0]<=c[0]){
Map[tp]={c[0]+1, x,y};
}
}
}
}
Map.erase(Map.begin());
}
if(xx==-1 && yy==-1){
return imp;
}
Map = Map2;
vi res;
vc<pii> Z;
while(xx){
res.pb(A[xx-1]);
Z.pb({xx,yy});
auto [t,nx,ny] = Map[{xx,yy}];
xx=nx,yy=ny;
}
reverse(all(Z));
reverse(all(res));
per(i,si(res)){
int t = res[i];
auto [x,y] =Z[i];
int e = si(res)-1;
if(PP[t]) e = PP[t];
PP[t] = i;
int t1 = RightA(t, x+1);
int t2 = RightB(t, y+1);
if(t1 <= n && t2 <= m){
if(IT.Get(i+1,e,t1+1,0) > t2){
return {-1};
}
}
int ny = IT.Get(i+1,e,x+1,0);
int nx = IT.Get(i+1,e,y+1,1);
nx = LeftA(t,nx-1);
ny = LeftB(t,ny-1);
int ck=0;
if(nx > x) IT.Put(i, pii(nx,y)), ck=1;
if(ny > y) IT.Put(i, pii(y,nx)), ck=1;
if(!ck) IT.Put(i,pii(x,y));
}
return res;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 18ms
memory: 70784kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 10 10 7 1 9 2 3 5 0 6 8 4 7 1 9 2 3 5 0 6 8 4
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 10 7 1 9 2 3 5 0 6 8 4
result:
ok
Test #2:
score: 3
Accepted
time: 11ms
memory: 70832kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 10 10 7 9 4 5 6 8 2 1 3 0 7 9 4 5 8 6 2 1 3 0
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1 -1
result:
ok
Test #3:
score: 3
Accepted
time: 8ms
memory: 70240kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 1000 1000 227 14 144 355 329 614 282 987 90 67 421 904 584 672 129 286 187 498 450 29 342 688 521 133 585 769 794 138 731 946 28 996 402 935 96 855 2 186 361 1 451 914 318 720 296 389 356 364 400 971 387 979 520 885 604 62 814 474 479 952 394 640 959 246 509 171 486 ...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1000 227 14 144 355 329 614 282 987 90 67 421 904 584 672 129 286 187 498 450 29 342 688 521 133 585 769 794 138 731 946 28 996 402 935 96 855 2 186 361 1 451 914 318 720 296 389 356 364 400 971 387 979 520 885 604 62 814 474 479 952 394 640 959 246 509 171 486 35...
result:
ok
Test #4:
score: 3
Accepted
time: 11ms
memory: 69940kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 997 997 615 691 867 398 544 236 744 802 466 701 700 106 636 993 668 105 409 810 957 249 619 293 729 339 189 537 70 237 487 360 276 693 181 954 85 310 669 52 86 12 209 787 294 188 64 561 828 44 564 480 895 283 289 924 192 783 890 948 674 279 114 229 822 771 458 179 65...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1 -1
result:
ok
Test #5:
score: 3
Accepted
time: 230ms
memory: 110988kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 19751 36170 33104 26686 54203 5214 37609 58763 10536 82655 80942 70794 54794 16739 55137 38172 11159 41408 34850 54300 58781 6684 19791 28867 83340 19360 7277 54060 59942 87198 45397 49198 66950 26865 7468 7059 58566 43804 99565 76536 48614 34101 26106 ...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 100000 19751 36170 33104 26686 54203 5214 37609 58763 10536 82655 80942 70794 54794 16739 55137 38172 11159 41408 34850 54300 58781 6684 19791 28867 83340 19360 7277 54060 59942 87198 45397 49198 66950 26865 7468 7059 58566 43804 99565 76536 48614 34101 26106 5596...
result:
ok
Test #6:
score: 3
Accepted
time: 36ms
memory: 78312kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 57387 11861 84433 84680 51764 17643 86122 83141 74972 47794 40972 60391 93655 62206 23852 51121 39250 5924 83139 29296 56131 49532 51226 82006 3512 64857 97761 67854 81216 44976 43459 57540 14182 6532 49925 71980 75037 14724 22961 5863 51568 85048 44306...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1 -1
result:
ok
Test #7:
score: 3
Accepted
time: 35ms
memory: 79652kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 84974 12498 84270 93621 94069 64811 16796 8508 5403 97838 69731 94154 34731 38790 45254 19912 63443 17097 25188 8738 22665 3307 92076 63795 24089 54926 82925 31639 81818 84608 65732 50776 53506 41939 34765 62498 39249 80937 95327 706 45760 39603 10343 6...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1 -1
result:
ok
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 15
Accepted
time: 188ms
memory: 99748kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 89984 90016 167910 187180 47437 150113 199404 61979 49501 155514 167910 175137 104441 149717 155514 13573 170025 181983 117868 13573 149717 166954 145922 29787 93788 58581 158693 51768 120499 17700 17700 4746 119328 33450 138501 137246 33450 135751 84363 168724 15701...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 60000 187180 47437 150113 199404 61979 49501 167910 175137 104441 155514 170025 181983 117868 13573 149717 166954 145922 29787 93788 58581 158693 51768 120499 17700 4746 119328 138501 137246 33450 135751 84363 168724 157010 108760 44137 113102 139611 199377 86291 ...
result:
ok
Test #9:
score: 15
Accepted
time: 182ms
memory: 100352kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 90003 90000 14155 14155 151711 151711 31573 66800 139383 1925 46366 116207 18428 18428 66618 83155 133084 9526 176340 87155 193385 52734 133084 1925 79878 137917 176340 32150 15872 66618 116207 194766 40942 31265 147928 124727 97615 58260 161323 8229 74777 146601 959...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 60001 14155 151711 31573 66800 139383 46366 18428 83155 9526 87155 193385 52734 133084 1925 79878 137917 176340 32150 15872 66618 116207 194766 40942 31265 147928 124727 97615 58260 161323 8229 74777 146601 37955 95987 118028 29763 15233 101780 54731 36231 65482 3...
result:
ok
Test #10:
score: 0
Wrong Answer
time: 204ms
memory: 101240kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 89985 90021 192793 185974 48491 162906 75646 99166 183316 75646 52957 33987 83321 64287 83321 123979 130761 130761 154020 134587 154020 186921 178874 71496 184891 82981 123873 186777 127271 139973 67220 127271 140236 191126 67220 36003 36003 23064 43454 116351 168977...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 60002 192793 185974 48491 162906 99166 183316 75646 52957 33987 64287 83321 123979 130761 134587 154020 186921 178874 71496 184891 82981 123873 186777 139973 127271 140236 191126 67220 36003 23064 43454 116351 168977 63200 132243 153847 21074 108613 25083 115379 5...
result:
wrong answer 3rd lines differ - on the 1st token, expected: '1', found: '60002'
Subtask #3:
score: 0
Wrong Answer
Test #71:
score: 0
Wrong Answer
time: 529ms
memory: 135980kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 0 1 0 0 1 1 1 1 0 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 1 0 1 1 1 0 1 0...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1 -1
result:
wrong answer 3rd lines differ - on the 1st token, expected: '85671', found: '1'
Subtask #4:
score: 0
Wrong Answer
Test #97:
score: 16
Accepted
time: 50ms
memory: 77512kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 20000 30000 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 20000 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955 110955...
result:
ok
Test #98:
score: 16
Accepted
time: 187ms
memory: 101540kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 99999 88888 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 224...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 88886 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 22478 ...
result:
ok
Test #99:
score: 16
Accepted
time: 178ms
memory: 103256kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 166304 166304 166304 166304 166304 166304 166304 166304 102708 11497 11497 11497 11497 11497 11497 11497 11497 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 125776 125776 125776 125776 125776 125776 125776 125...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 85709 166304 166304 166304 166304 166304 166304 166304 102708 11497 11497 11497 11497 11497 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 17510 125776 125776 125776 125776 125776 125776 125776 125776 125776 125776 125776 125776 125776 125776 12...
result:
ok
Test #100:
score: 16
Accepted
time: 209ms
memory: 104736kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 1...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 95801 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117 117117...
result:
ok
Test #101:
score: 16
Accepted
time: 193ms
memory: 105572kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 1...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 98803 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501 127501...
result:
ok
Test #102:
score: 16
Accepted
time: 200ms
memory: 105340kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 100000 100000 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 1...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 99078 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473 116473...
result:
ok
Test #103:
score: 0
Wrong Answer
time: 57ms
memory: 85020kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 90001 89999 171539 66534 9757 176662 84211 83487 129394 86197 172362 142984 93418 146577 96159 191701 83516 196081 37110 105351 165140 54539 124569 187177 24718 194979 119131 15727 40820 31718 13095 147840 76889 199389 75862 118045 115442 10325 157261 11275 83362 174...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1 -1
result:
wrong answer 3rd lines differ - on the 1st token, expected: '69029', found: '1'
Subtask #5:
score: 0
Wrong Answer
Test #132:
score: 0
Wrong Answer
time: 7ms
memory: 71952kb
input:
vHwzrZUx9chlYIJ7zODvOcQbZwj3OxhB 2800 2999 47 51 42 122 38 125 170 11 119 48 289 297 27 150 207 271 11 15 67 287 149 220 76 274 128 151 60 117 39 123 254 75 170 198 72 179 274 203 13 88 139 153 46 288 13 282 16 219 284 91 274 63 190 157 72 286 238 1 219 82 82 31 285 128 198 172 161 271 36 111 160 26...
output:
IyRwUZ9rsuq5tjuK54lpSvORqGQyBWEZ OK 1 -1
result:
wrong answer 3rd lines differ - on the 1st token, expected: '2800', found: '1'
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%