답안 #975384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975384 2024-05-05T05:07:50 Z modwwe Passport (JOI23_passport) C++17
100 / 100
854 ms 179960 KB
#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
}
}

Compilation message

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)
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 40280 KB Output is correct
2 Correct 10 ms 40284 KB Output is correct
3 Correct 9 ms 40284 KB Output is correct
4 Correct 809 ms 179416 KB Output is correct
5 Correct 331 ms 76452 KB Output is correct
6 Correct 215 ms 71612 KB Output is correct
7 Correct 131 ms 71596 KB Output is correct
8 Correct 106 ms 74424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 40284 KB Output is correct
2 Correct 9 ms 40284 KB Output is correct
3 Correct 9 ms 40284 KB Output is correct
4 Correct 10 ms 40372 KB Output is correct
5 Correct 9 ms 40284 KB Output is correct
6 Correct 10 ms 40184 KB Output is correct
7 Correct 9 ms 40128 KB Output is correct
8 Correct 10 ms 40280 KB Output is correct
9 Correct 9 ms 40284 KB Output is correct
10 Correct 9 ms 40284 KB Output is correct
11 Correct 10 ms 40496 KB Output is correct
12 Correct 10 ms 40280 KB Output is correct
13 Correct 10 ms 40280 KB Output is correct
14 Correct 9 ms 40280 KB Output is correct
15 Correct 10 ms 40284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 40284 KB Output is correct
2 Correct 9 ms 40284 KB Output is correct
3 Correct 9 ms 40284 KB Output is correct
4 Correct 10 ms 40372 KB Output is correct
5 Correct 9 ms 40284 KB Output is correct
6 Correct 10 ms 40184 KB Output is correct
7 Correct 9 ms 40128 KB Output is correct
8 Correct 10 ms 40280 KB Output is correct
9 Correct 9 ms 40284 KB Output is correct
10 Correct 9 ms 40284 KB Output is correct
11 Correct 10 ms 40496 KB Output is correct
12 Correct 10 ms 40280 KB Output is correct
13 Correct 10 ms 40280 KB Output is correct
14 Correct 9 ms 40280 KB Output is correct
15 Correct 10 ms 40284 KB Output is correct
16 Correct 15 ms 41308 KB Output is correct
17 Correct 13 ms 40796 KB Output is correct
18 Correct 14 ms 41308 KB Output is correct
19 Correct 14 ms 41308 KB Output is correct
20 Correct 11 ms 40796 KB Output is correct
21 Correct 11 ms 40664 KB Output is correct
22 Correct 12 ms 40640 KB Output is correct
23 Correct 13 ms 41200 KB Output is correct
24 Correct 12 ms 41052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 40284 KB Output is correct
2 Correct 9 ms 40284 KB Output is correct
3 Correct 9 ms 40284 KB Output is correct
4 Correct 10 ms 40372 KB Output is correct
5 Correct 9 ms 40284 KB Output is correct
6 Correct 10 ms 40184 KB Output is correct
7 Correct 9 ms 40128 KB Output is correct
8 Correct 10 ms 40280 KB Output is correct
9 Correct 9 ms 40284 KB Output is correct
10 Correct 9 ms 40284 KB Output is correct
11 Correct 10 ms 40496 KB Output is correct
12 Correct 10 ms 40280 KB Output is correct
13 Correct 10 ms 40280 KB Output is correct
14 Correct 9 ms 40280 KB Output is correct
15 Correct 10 ms 40284 KB Output is correct
16 Correct 15 ms 41308 KB Output is correct
17 Correct 13 ms 40796 KB Output is correct
18 Correct 14 ms 41308 KB Output is correct
19 Correct 14 ms 41308 KB Output is correct
20 Correct 11 ms 40796 KB Output is correct
21 Correct 11 ms 40664 KB Output is correct
22 Correct 12 ms 40640 KB Output is correct
23 Correct 13 ms 41200 KB Output is correct
24 Correct 12 ms 41052 KB Output is correct
25 Correct 9 ms 40280 KB Output is correct
26 Correct 9 ms 40284 KB Output is correct
27 Correct 14 ms 41308 KB Output is correct
28 Correct 13 ms 40796 KB Output is correct
29 Correct 12 ms 40936 KB Output is correct
30 Correct 12 ms 40796 KB Output is correct
31 Correct 12 ms 41052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 40280 KB Output is correct
2 Correct 10 ms 40284 KB Output is correct
3 Correct 9 ms 40284 KB Output is correct
4 Correct 809 ms 179416 KB Output is correct
5 Correct 331 ms 76452 KB Output is correct
6 Correct 215 ms 71612 KB Output is correct
7 Correct 131 ms 71596 KB Output is correct
8 Correct 106 ms 74424 KB Output is correct
9 Correct 10 ms 40284 KB Output is correct
10 Correct 9 ms 40284 KB Output is correct
11 Correct 9 ms 40284 KB Output is correct
12 Correct 10 ms 40372 KB Output is correct
13 Correct 9 ms 40284 KB Output is correct
14 Correct 10 ms 40184 KB Output is correct
15 Correct 9 ms 40128 KB Output is correct
16 Correct 10 ms 40280 KB Output is correct
17 Correct 9 ms 40284 KB Output is correct
18 Correct 9 ms 40284 KB Output is correct
19 Correct 10 ms 40496 KB Output is correct
20 Correct 10 ms 40280 KB Output is correct
21 Correct 10 ms 40280 KB Output is correct
22 Correct 9 ms 40280 KB Output is correct
23 Correct 10 ms 40284 KB Output is correct
24 Correct 15 ms 41308 KB Output is correct
25 Correct 13 ms 40796 KB Output is correct
26 Correct 14 ms 41308 KB Output is correct
27 Correct 14 ms 41308 KB Output is correct
28 Correct 11 ms 40796 KB Output is correct
29 Correct 11 ms 40664 KB Output is correct
30 Correct 12 ms 40640 KB Output is correct
31 Correct 13 ms 41200 KB Output is correct
32 Correct 12 ms 41052 KB Output is correct
33 Correct 9 ms 40280 KB Output is correct
34 Correct 9 ms 40284 KB Output is correct
35 Correct 14 ms 41308 KB Output is correct
36 Correct 13 ms 40796 KB Output is correct
37 Correct 12 ms 40936 KB Output is correct
38 Correct 12 ms 40796 KB Output is correct
39 Correct 12 ms 41052 KB Output is correct
40 Correct 854 ms 179960 KB Output is correct
41 Correct 355 ms 80056 KB Output is correct
42 Correct 635 ms 131452 KB Output is correct
43 Correct 619 ms 157772 KB Output is correct
44 Correct 263 ms 72884 KB Output is correct
45 Correct 294 ms 79700 KB Output is correct
46 Correct 134 ms 62140 KB Output is correct
47 Correct 422 ms 114584 KB Output is correct
48 Correct 271 ms 104008 KB Output is correct