QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#63539 | #5034. >.< | Appleblue17 | 0 | 339ms | 126976kb | C++14 | 3.0kb | 2022-11-22 16:09:28 | 2022-11-22 16:09:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ls(o) tr[o].ls
#define rs(o) tr[o].rs
const int N=2e5+5,INF=1e9;
int n,m,k;
vector <int> ED;
vector < pair<int,int> > G[N];
map <int,int> mp[N];
int ct=1;
bool tag[N];
struct segtree{
int ls,rs,val,siz,w;
}tr[N*32];
int rt[N],cnt;
int modify0(int l,int r,int o,int pos,int w){
cnt++,tr[cnt]=tr[o],o=cnt;
if(l==r){
tr[o].siz=1,tr[o].w=w;
return o;
}
int mid=(l+r)>>1;
if(pos<=mid) ls(o)=modify0(l,mid,ls(o),pos,w);
else rs(o)=modify0(mid+1,r,rs(o),pos,w);
tr[o].siz=tr[ls(o)].siz+tr[rs(o)].siz;
return o;
}
int modify(int l,int r,int o,int pos,int x){
cnt++,tr[cnt]=tr[o],o=cnt;
if(l==r){
tr[o].val=x;
return o;
}
int mid=(l+r)>>1;
if(pos<=mid) ls(o)=modify(l,mid,ls(o),pos,x);
else rs(o)=modify(mid+1,r,rs(o),pos,x);
tr[o].siz=tr[ls(o)].siz+tr[rs(o)].siz;
return o;
}
int query(int l,int r,int o,int pos){
if(l==r){
return tr[o].val;
}
int mid=(l+r)>>1;
if(pos<=mid) return query(l,mid,ls(o),pos);
else return query(mid+1,r,rs(o),pos);
}
void pr(int l,int r,int o){
if(!o) return ;
cout<<l<<" "<<r<<" "<<o<<": "<<tr[o].val<<'\n';
int mid=(l+r)>>1;
pr(l,mid,ls(o));
pr(mid+1,r,rs(o));
}
int fail[N];
queue <int> q;
void getnxt(){
q.push(1);
while(q.size()){
int u=q.front(); q.pop();
rt[u]=rt[fail[u]];
if(u-1>=1 && u-1<=n){
for(auto i: G[u-1]){
int v=i.first,w=i.second;
rt[u]=modify0(1,n,rt[u],v,w);
}
}
for(auto i: mp[u]){
int c=i.first,v=i.second;
if(c==n) ED.push_back(v);
fail[v]=query(1,n,rt[u],c);
// cout<<"FAIL "<<v<<" "<<fail[v]<<'\n';
rt[u]=modify(1,n,rt[u],c,v);
q.push(v);
}
}
}
struct abc{
int u,dis;
};
bool operator <(abc X,abc Y){
return X.dis>Y.dis;
}
priority_queue <abc> Q;
int dis[N];
void search(int l,int r,int o,int st){
if(!tr[o].siz) return ;
if(l==r){
int v=tr[o].val,w=tr[o].w;
dis[v]=st+w;
Q.push({v,st+w});
tr[o].siz=0;
return ;
}
int mid=(l+r)>>1;
search(l,mid,ls(o),st);
search(mid+1,r,rs(o),st);
tr[o].siz=tr[ls(o)].siz+tr[rs(o)].siz;
}
int main(){
cin>>n>>m>>k;
for(int i=1;i<=m;i++){
int u,v,w; cin>>u>>v>>w;
G[u].push_back(make_pair(v,w));
}
for(int i=1;i<=n;i++) mp[0][i]=1;
for(int i=1;i<=n;i++) mp[1][i]=++ct;
for(int i=1;i<=k;i++){
int len; cin>>len;
int x=1;
for(int t=1;t<=len;t++){
int c; cin>>c;
if(!mp[x][c]) mp[x][c]=++ct;
x=mp[x][c];
}
tag[x]=1;
}
for(int u=1;u<=ct;u++){
// cout<<u<<": ";
for(auto i: mp[u]){
int c=i.first,v=i.second;
// cout<<"["<<c<<"]"<<v<<" ";
}
// cout<<'\n';
}
rt[0]=++cnt;
for(int i=1;i<=n;i++) rt[0]=modify(1,n,rt[0],i,mp[0][i]);
getnxt();
for(int i=1;i<=ct;i++) dis[i]=INF;
dis[2]=0; Q.push({2,0});
while(Q.size()){
int u=Q.top().u; Q.pop();
search(1,n,rt[u],dis[u]);
}
// for(int i=1;i<=ct;i++) cout<<dis[i]<<" ";
// cout<<'\n';
// for(int x: ED) cout<<x<<" ";
cout<<dis[n+1];
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 18724kb
input:
35 100 0 34 7 447733879 24 20 187005344 14 34 654502303 2 31 865194349 20 33 9517055 33 15 991889891 24 33 395599993 13 16 237525328 9 5 373850826 30 34 391470240 10 7 650077565 26 10 400825980 34 27 189924713 19 27 907609573 20 10 614945312 10 5 960007605 1 7 984076202 32 25 539699728 24 31 2553027...
output:
-1139345098
result:
wrong answer 1st lines differ - expected: '1970522617', found: '-1139345098'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 339ms
memory: 126976kb
input:
50000 200000 1 7542 37166 116613326 3581 43961 629220971 12873 42953 440313807 31744 5286 697832848 25882 12748 106667302 34760 29676 181570340 41570 9240 885513989 22227 35688 63657981 43180 29194 174058940 8977 41899 48262624 7465 18291 600002514 46925 9281 951474878 2115 31162 373758881 5386 3798...
output:
773241160
result:
wrong answer 1st lines differ - expected: '2526392504', found: '773241160'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%