提交记录 4981


用户 题目 状态 得分 用时 内存 语言 代码长度
psk011102 noi18a. 【NOI2018】归程 Accepted 100 2.39 s 236044 KB C++11 4.11 KB
提交时间 评测时间
2018-08-03 14:13:13 2020-08-01 00:09:37
// luogu-judger-enable-o2
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;
bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}
inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
using namespace std;
const int MAX_N = 220000;
int he[200005],to[800005],ne[800005],cost[800005],e;
struct node{
  int u,v,hei,len;
}p[400005];
int fa[200005];
int ls[200005*60],rs[200005*60],mindep[200005*60],dep[200005],lst[200005*60];
int n,m,cnt,root[200005*60];
int len[200005];
void add(int x,int y,int z){
     to[++e]=y;
     ne[e]=he[x];
     he[x]=e;
     cost[e]=z;
}
long long dis[200005];
int h[400005];
#define PII pair<long long,int>
priority_queue<PII,vector<PII> ,greater<PII> >Q;
void spfa(){
    F(i,1,n)dis[i]=1e15;
   dis[1]=0;
   Q.push(make_pair(dis[1],1));
   while(!Q.empty()){
    PII now=Q.top();
    Q.pop();
    for(int i=he[now.second];i;i=ne[i]){
         int v=to[i];
        if(dis[now.second]+cost[i]<dis[v]){
            dis[v]=dis[now.second]+cost[i];
              Q.push(make_pair(dis[v],v));
        }
    }
   }
}
bool cmp(node x,node y){
  return x.hei>y.hei;
}
#define mid ((l+r)>>1)
void built(int &rt,int l,int r){
      rt=++cnt;
      if(l==r){
          lst[rt]=l;
          mindep[rt]=dis[l];
          return ;
      }
     built(ls[rt],l,mid);
     built(rs[rt],mid+1,r);
}
void update(int &rt,int pre,int l,int r,int x,int val){
    rt=++cnt;
    ls[rt]=ls[pre];
    rs[rt]=rs[pre];
    if(l==r){
       mindep[rt]=val;
       lst[rt]=lst[pre];
       return ;
    }
    if(x<=mid)update(ls[rt],ls[pre],l,mid,x,val);
    else update(rs[rt],rs[pre],mid+1,r,x,val);
}
void modify(int &rt,int pre,int l,int r,int x,int val){
   rt=++cnt;
   ls[rt]=ls[pre];
   rs[rt]=rs[pre];
   if(l==r){
       lst[rt]=val;
       mindep[rt]=mindep[pre];
       return ;
   }
   if(x<=mid)modify(ls[rt],ls[pre],l,mid,x,val);
   else modify(rs[rt],rs[pre],mid+1,r,x,val);
}
int querymin(int rt,int l,int r,int x){
       if(l==r)return mindep[rt];
       if(x<=mid)return querymin(ls[rt],l,mid,x);
       else  return querymin(rs[rt],mid+1,r,x);
}
int querypre(int rt,int l,int r,int x){
   if(l==r)return lst[rt];
   if(x<=mid)return querypre(ls[rt],l,mid,x);
   else return querypre(rs[rt],mid+1,r,x);
}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void merge(int x,int y,int id){
    int xx,yy;
    xx=find(x),yy=find(y);
    if(dep[xx]<dep[yy])swap(xx,yy);
    fa[yy]=xx;
    if(dep[yy]==dep[xx])dep[xx]++;
    modify(root[id],root[id-1],1,n,yy,xx);
    if(chkmin(len[xx],len[yy]))update(root[id],root[id],1,n,xx,len[xx]);
}
int main(){
    int t=read();
    while(t--){
    Set(he,0);
    e=0;
    Set(ls,0);
    Set(rs,0);
    Set(root,0);
    cnt=0;
    n=read();
    m=read();
    F(i,1,m){
      p[i].u=read();
      p[i].v=read();
      p[i].len=read();
      p[i].hei=read();
      add(p[i].u,p[i].v,p[i].len);
      add(p[i].v,p[i].u,p[i].len);
    }
    spfa();
    F(i,1,n)fa[i]=i,len[i]=dis[i],dep[i]=1;
    built(root[0],1,n);
    sort(p+1,p+m+1,cmp);
    F(i,1,m){
            int a=p[i].u,b=p[i].v;
            merge(a,b,i);
            h[i]=p[i].hei;
    }
    int q=read(),k=read(),s=read();
    long long lstans=0;
    while(q--){
       int v=read(),p=read();
         v=(v+k*lstans-1)%n+1;
         p=(p+k*lstans)%(s+1);
         int ll=1,rr=m,ret=0;
         while(ll<=rr){
            int Mid=(ll+rr)>>1;
            if(h[Mid]>p){
                ll=Mid+1;
                ret=Mid;
            }
            else rr=Mid-1;
         }
         int Pre;
          while(1){
            Pre=querypre(root[ret],1,n,v);
            if(v==Pre)break;
            v=Pre;
        }
        lstans=querymin(root[ret],1,n,v);
            printf("%lld\n",lstans);
    }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #121.38 ms138 MB + 160 KBAcceptedScore: 5

Testcase #221.394 ms138 MB + 180 KBAcceptedScore: 5

Testcase #321.501 ms138 MB + 200 KBAcceptedScore: 5

Testcase #421.711 ms138 MB + 216 KBAcceptedScore: 5

Testcase #525.389 ms138 MB + 836 KBAcceptedScore: 5

Testcase #6859.342 ms230 MB + 524 KBAcceptedScore: 5

Testcase #724.818 ms138 MB + 536 KBAcceptedScore: 5

Testcase #824.852 ms138 MB + 540 KBAcceptedScore: 5

Testcase #924.866 ms138 MB + 540 KBAcceptedScore: 5

Testcase #101.029 s201 MB + 180 KBAcceptedScore: 5

Testcase #111.024 s201 MB + 208 KBAcceptedScore: 5

Testcase #121.137 s225 MB + 948 KBAcceptedScore: 5

Testcase #131.136 s225 MB + 280 KBAcceptedScore: 5

Testcase #141.142 s226 MB + 976 KBAcceptedScore: 5

Testcase #1526.545 ms138 MB + 820 KBAcceptedScore: 5

Testcase #1626.524 ms138 MB + 816 KBAcceptedScore: 5

Testcase #171.141 s225 MB + 40 KBAcceptedScore: 5

Testcase #181.133 s226 MB + 132 KBAcceptedScore: 5

Testcase #192.39 s229 MB + 932 KBAcceptedScore: 5

Testcase #202.365 s230 MB + 308 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:43:22 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠