답안 #975387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975387 2024-05-05T05:10:10 Z modwwe Passport (JOI23_passport) C++17
100 / 100
736 ms 106344 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(int, int, int)':
passport.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |      int mid=l+r>>1;
      |              ~^~
passport.cpp: In function 'void upd(int, int, int, int, int, int)':
passport.cpp:74:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |     int mid=l+r>>1;
      |             ~^~
passport.cpp: In function 'void get(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 15 ms 29784 KB Output is correct
2 Correct 12 ms 29904 KB Output is correct
3 Correct 10 ms 29788 KB Output is correct
4 Correct 675 ms 105644 KB Output is correct
5 Correct 311 ms 53872 KB Output is correct
6 Correct 178 ms 51384 KB Output is correct
7 Correct 139 ms 51208 KB Output is correct
8 Correct 82 ms 53064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30036 KB Output is correct
2 Correct 15 ms 29788 KB Output is correct
3 Correct 12 ms 29788 KB Output is correct
4 Correct 13 ms 29788 KB Output is correct
5 Correct 14 ms 29940 KB Output is correct
6 Correct 15 ms 29848 KB Output is correct
7 Correct 13 ms 29784 KB Output is correct
8 Correct 14 ms 29788 KB Output is correct
9 Correct 13 ms 29788 KB Output is correct
10 Correct 12 ms 29788 KB Output is correct
11 Correct 11 ms 29788 KB Output is correct
12 Correct 12 ms 29788 KB Output is correct
13 Correct 12 ms 29952 KB Output is correct
14 Correct 14 ms 29784 KB Output is correct
15 Correct 11 ms 29788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30036 KB Output is correct
2 Correct 15 ms 29788 KB Output is correct
3 Correct 12 ms 29788 KB Output is correct
4 Correct 13 ms 29788 KB Output is correct
5 Correct 14 ms 29940 KB Output is correct
6 Correct 15 ms 29848 KB Output is correct
7 Correct 13 ms 29784 KB Output is correct
8 Correct 14 ms 29788 KB Output is correct
9 Correct 13 ms 29788 KB Output is correct
10 Correct 12 ms 29788 KB Output is correct
11 Correct 11 ms 29788 KB Output is correct
12 Correct 12 ms 29788 KB Output is correct
13 Correct 12 ms 29952 KB Output is correct
14 Correct 14 ms 29784 KB Output is correct
15 Correct 11 ms 29788 KB Output is correct
16 Correct 15 ms 30556 KB Output is correct
17 Correct 13 ms 30300 KB Output is correct
18 Correct 15 ms 30556 KB Output is correct
19 Correct 15 ms 30556 KB Output is correct
20 Correct 12 ms 30296 KB Output is correct
21 Correct 12 ms 30040 KB Output is correct
22 Correct 10 ms 30044 KB Output is correct
23 Correct 13 ms 30296 KB Output is correct
24 Correct 13 ms 30296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 30036 KB Output is correct
2 Correct 15 ms 29788 KB Output is correct
3 Correct 12 ms 29788 KB Output is correct
4 Correct 13 ms 29788 KB Output is correct
5 Correct 14 ms 29940 KB Output is correct
6 Correct 15 ms 29848 KB Output is correct
7 Correct 13 ms 29784 KB Output is correct
8 Correct 14 ms 29788 KB Output is correct
9 Correct 13 ms 29788 KB Output is correct
10 Correct 12 ms 29788 KB Output is correct
11 Correct 11 ms 29788 KB Output is correct
12 Correct 12 ms 29788 KB Output is correct
13 Correct 12 ms 29952 KB Output is correct
14 Correct 14 ms 29784 KB Output is correct
15 Correct 11 ms 29788 KB Output is correct
16 Correct 15 ms 30556 KB Output is correct
17 Correct 13 ms 30300 KB Output is correct
18 Correct 15 ms 30556 KB Output is correct
19 Correct 15 ms 30556 KB Output is correct
20 Correct 12 ms 30296 KB Output is correct
21 Correct 12 ms 30040 KB Output is correct
22 Correct 10 ms 30044 KB Output is correct
23 Correct 13 ms 30296 KB Output is correct
24 Correct 13 ms 30296 KB Output is correct
25 Correct 13 ms 29912 KB Output is correct
26 Correct 11 ms 29784 KB Output is correct
27 Correct 16 ms 30548 KB Output is correct
28 Correct 14 ms 30300 KB Output is correct
29 Correct 10 ms 30552 KB Output is correct
30 Correct 14 ms 30044 KB Output is correct
31 Correct 13 ms 30296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 29784 KB Output is correct
2 Correct 12 ms 29904 KB Output is correct
3 Correct 10 ms 29788 KB Output is correct
4 Correct 675 ms 105644 KB Output is correct
5 Correct 311 ms 53872 KB Output is correct
6 Correct 178 ms 51384 KB Output is correct
7 Correct 139 ms 51208 KB Output is correct
8 Correct 82 ms 53064 KB Output is correct
9 Correct 8 ms 30036 KB Output is correct
10 Correct 15 ms 29788 KB Output is correct
11 Correct 12 ms 29788 KB Output is correct
12 Correct 13 ms 29788 KB Output is correct
13 Correct 14 ms 29940 KB Output is correct
14 Correct 15 ms 29848 KB Output is correct
15 Correct 13 ms 29784 KB Output is correct
16 Correct 14 ms 29788 KB Output is correct
17 Correct 13 ms 29788 KB Output is correct
18 Correct 12 ms 29788 KB Output is correct
19 Correct 11 ms 29788 KB Output is correct
20 Correct 12 ms 29788 KB Output is correct
21 Correct 12 ms 29952 KB Output is correct
22 Correct 14 ms 29784 KB Output is correct
23 Correct 11 ms 29788 KB Output is correct
24 Correct 15 ms 30556 KB Output is correct
25 Correct 13 ms 30300 KB Output is correct
26 Correct 15 ms 30556 KB Output is correct
27 Correct 15 ms 30556 KB Output is correct
28 Correct 12 ms 30296 KB Output is correct
29 Correct 12 ms 30040 KB Output is correct
30 Correct 10 ms 30044 KB Output is correct
31 Correct 13 ms 30296 KB Output is correct
32 Correct 13 ms 30296 KB Output is correct
33 Correct 13 ms 29912 KB Output is correct
34 Correct 11 ms 29784 KB Output is correct
35 Correct 16 ms 30548 KB Output is correct
36 Correct 14 ms 30300 KB Output is correct
37 Correct 10 ms 30552 KB Output is correct
38 Correct 14 ms 30044 KB Output is correct
39 Correct 13 ms 30296 KB Output is correct
40 Correct 736 ms 106344 KB Output is correct
41 Correct 355 ms 55700 KB Output is correct
42 Correct 579 ms 81344 KB Output is correct
43 Correct 578 ms 94760 KB Output is correct
44 Correct 215 ms 52540 KB Output is correct
45 Correct 243 ms 56380 KB Output is correct
46 Correct 123 ms 44252 KB Output is correct
47 Correct 357 ms 73316 KB Output is correct
48 Correct 286 ms 68872 KB Output is correct