제출 #975384

#제출 시각아이디문제언어결과실행 시간메모리
975384modwwePassport (JOI23_passport)C++17
100 / 100
854 ms179960 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
void ngha();
const int mod2=1e9+7;
const int  mod1=998244353;
struct ib
{
    int a;
    int b;
};
struct icd
{
    int a,b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c, d,e;

};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int  i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
    /// fin(task),fou(task);
//#endif
    NHP
//modwwe
    //  cin>>res;
    ngha();

}
vector<ib> v[800001];
int c[200001];

void build(int node,int l,int r)
{v[node].pb({node/2,0});
     if(l==r){c[l]=node; return;}
     int mid=l+r>>1;
      build(node<<1,l,mid);
      build(node<<1|1,mid+1,r);
}
void upd(int node,int l,int r,int l1,int r1,int z)
{
    if(l>r1||r<l1) { return;}
    if(l>=l1&&r<=r1)
    {
         v[node].pb({c[z],1});
         return;
    }
    int mid=l+r>>1;
     upd(node<<1,l,mid,l1,r1,z);
     upd(node<<1|1,mid+1,r,l1,r1,z);
}
    deque <int> q;
    bool b[800001];
    int d[800001][2];
    int f[800001];
void get(int z)
{
for(int i=1;i<=800000;i++)
    d[i][z]=1e9;

    if(z==0)
 {
      q.push_back(c[1]);
      d[c[1]][0]=-1;
 }
 else {
        q.push_back(c[n]); d[c[n]][1]=-1;}
    memset(b,0,sizeof b);

        while(!q.empty())
        {
             int u=q.front();
             q.pop_front();
             ///if(z==1) cout<<u,down
              if(b[u]) continue;
               b[u]=1;
for(auto x:v[u])
{/// if(z==1) cout<<x.a<<" "<<u<<" "<<z,down
     if(d[x.a][z]>d[u][z]+x.b)
     {d[x.a][z]=d[u][z]+x.b;
         if(x.b)q.push_back(x.a);
         else q.push_front(x.a);
     }
}
        }
        d[c[1]][0]=0;
        d[c[n]][1]=0;
}
struct cmp
{
     bool operator()(ib a,ib b)
     {
         return a.a>b.a;
     }
};
void ngha()
{
     cin>>n;
     build(1,1,n);
      for(int i=1;i<=n;i++){
         cin>>l>>r;
         upd(1,1,n,l,r,i);
         }
         get(0);
         get(1);
priority_queue<ib,vector<ib>,cmp> p;
for(int i=1;i<=n;i++)
{
    if(d[c[i]][0]+d[c[i]][1]+1<=n)
 p.push({d[c[i]][0]+d[c[i]][1]+1,c[i]});
}
memset(f,-1,sizeof f);
while(!p.empty())
{
    ib cx=p.top();
    p.pop();
     if(f[cx.b]!=-1) continue;
      f[cx.b]=cx.a;
      for(auto x:v[cx.b])
      {
            p.push({cx.a+x.b,x.a});
      }
}
cin>>m;
for(int i=1;i<=m;i++)
{
     cin>>l;
     cout<<f[c[l]],down
}
}

컴파일 시 표준 에러 (stderr) 메시지

passport.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
passport.cpp: In function 'void build(long long int, long long int, long long int)':
passport.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |      int mid=l+r>>1;
      |              ~^~
passport.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
passport.cpp:74:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |     int mid=l+r>>1;
      |             ~^~
passport.cpp: In function 'void get(long long int)':
passport.cpp:84:1: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   84 | for(int i=1;i<=800000;i++)
      | ^~~
passport.cpp:87:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   87 |     if(z==0)
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...