提交记录 4262


用户 题目 状态 得分 用时 内存 语言 代码长度
adoubiq noi18a. 【NOI2018】归程 Accepted 100 2.201 s 161988 KB C++ 3.42 KB
提交时间 评测时间
2018-07-19 13:23:41 2020-07-31 22:48:06
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstring>
#include<set>
#include<map>
#include<bitset>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int M=4e5+500,N=2e5+500;

//Do not use it while there are any strings
ll gti(void)
{
/*    static const int S=1<<16;
    static char buf[S],*p=buf+S;
#define getchar() ((p==buf+S?fread(p=buf,1,S,stdin):0),*p++)*/
    ll st=1,ret=0;
    char c=getchar();
    for (;!isdigit(c)&&c!='-';c=getchar());
    if (c=='-') st=-1,c=getchar();
    for (;isdigit(c);c=getchar()) ret=ret*10+c-'0';
//#undef getchar
    return ret*st;
}

int n,m;

struct edge
{
    edge *nxt;
    int f,t,l,a;
    bool operator<(const edge &b)const
    {
    return a>b.a;
    }
}pool[M*2],*pt[N],*p=pool,e[M];
void add(int a,int b,int c)
{
    *(++p)=(edge){pt[a],a,b,c,0},pt[a]=p;
    *(++p)=(edge){pt[b],b,a,c,0},pt[b]=p;
}

int dis[N];
struct P
{
    int id,dis;
    P(void):id(0),dis(0x7fffffff){}
    P(int a,int b):id(a),dis(b){}
    bool operator<(const P &b)const
    {
    return dis>b.dis;
    }
};
priority_queue<P> hp;
int sum=0;
void dijstra(void)
{
    memset(dis,127,sizeof(dis));
    dis[1]=0;
    while (hp.size()) hp.pop();
    hp.push(P(1,0));
    for (P i;hp.size();)
    {
    ++sum;
    for (i=hp.top(),hp.pop();i.dis!=dis[i.id]&&hp.size();i=hp.top(),hp.pop());
    for (edge *x=pt[i.id];x;x=x->nxt)
        if (dis[x->t]>dis[i.id]+x->l)
        dis[x->t]=dis[i.id]+x->l,hp.push(P(x->t,dis[x->t]));
    }
}

int fa[N],zh[N];
int getfa(int v)
{
    return fa[v]==v?v:fa[v]=getfa(fa[v]);
}

#define mid ((l+r)>>1)
struct segt
{
    int ls,rs,f,v;
}t[N*50];
int cnt=0,rt[M];
int build(int now=0,int l=1,int r=n)
{
    now=++cnt;
    if (l==r) t[now]=(segt){0,0,l,dis[l]};
    else t[now].ls=build(0,l,mid),t[now].rs=build(0,mid+1,r);
    return now;
}
void change(int lst,int &now,int loc,segt x,int l=1,int r=n)
{
    if (!now) t[now=++cnt]=t[lst];
    else t[++cnt]=t[now],now=cnt;
    if (l==r) t[now]=x;
    else if (loc<=mid) change(t[lst].ls,t[now].ls,loc,x,l,mid);
    else if (loc>mid) change(t[lst].rs,t[now].rs,loc,x,mid+1,r);
}
segt query(int now,int v,int l=1,int r=n)
{
    if (l==r) return t[now];
    if (v<=mid) return query(t[now].ls,v,l,mid);
    return query(t[now].rs,v,mid+1,r);
}
void merge(int lst,int &now,int a,int b)
{
    int af=getfa(a),fb=getfa(b);
    if (af==fb) return;
    int val=min(query(lst,af).v,query(lst,fb).v);
    a=af,b=fb;
    if (zh[a]<zh[b]) swap(a,b);
    zh[a]=max(zh[a],zh[b]+1),fa[b]=a;
    segt x=(segt){0,0,a,val};
    change(lst,now,a,x),change(lst,now,b,x);
}

void init(void)
{
    p=pool,cnt=0;
    memset(pt,0,sizeof(pt));
    for (int i=1;i<=n;i++)
    fa[i]=i,zh[i]=0;
    for (int i=0;i<=m;i++) rt[i]=0;
}

int main(void)
{
    int T=gti();
    while (T--)
    {
    n=gti(),m=gti();
    init();
    for (int i=1;i<=m;i++)
    {
        int u=gti(),v=gti(),l=gti(),a=gti();
        add(u,v,l);
        e[i]=(edge){NULL,u,v,l,a};
    }
    dijstra();
    rt[0]=build();
    sort(e+1,e+1+m);
    for (int i=1;i<=m;i++)
        rt[i]=rt[i-1],merge(rt[i-1],rt[i],e[i].f,e[i].t);
    int q=gti(),tp=gti(),mx=gti(),ans=0;
    for (int i=1;i<=q;i++)
    {
        int v=(gti()+tp*ans-1)%n+1,p=(gti()+tp*ans)%(mx+1);
        edge now=(edge){NULL,0,0,0,p};
        int s=rt[(lower_bound(e+1,e+1+m,now)-e)-1];
        segt x=query(s,v);
        while (x.f!=v)
           	v=x.f,x=query(s,v);
        ans=x.v;
        printf("%d\n",ans);
    }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1297.93 us2 MB + 344 KBAcceptedScore: 5

Testcase #2318.8 us2 MB + 348 KBAcceptedScore: 5

Testcase #3482.01 us2 MB + 372 KBAcceptedScore: 5

Testcase #4604.52 us2 MB + 400 KBAcceptedScore: 5

Testcase #54.419 ms3 MB + 256 KBAcceptedScore: 5

Testcase #6794.488 ms154 MB + 816 KBAcceptedScore: 5

Testcase #74.035 ms3 MB + 72 KBAcceptedScore: 5

Testcase #84.033 ms3 MB + 76 KBAcceptedScore: 5

Testcase #94.07 ms3 MB + 72 KBAcceptedScore: 5

Testcase #101.023 s141 MB + 212 KBAcceptedScore: 5

Testcase #111.021 s141 MB + 220 KBAcceptedScore: 5

Testcase #121.059 s154 MB + 764 KBAcceptedScore: 5

Testcase #131.055 s153 MB + 888 KBAcceptedScore: 5

Testcase #141.056 s154 MB + 620 KBAcceptedScore: 5

Testcase #155.436 ms3 MB + 252 KBAcceptedScore: 5

Testcase #165.414 ms3 MB + 252 KBAcceptedScore: 5

Testcase #171.059 s154 MB + 836 KBAcceptedScore: 5

Testcase #181.049 s154 MB + 820 KBAcceptedScore: 5

Testcase #192.201 s158 MB + 184 KBAcceptedScore: 5

Testcase #202.158 s158 MB + 196 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-26 07:15:10 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用