Submission #1111445

#TimeUsernameProblemLanguageResultExecution timeMemory
1111445StefanSebezGift Exchange (JOI24_ho_t4)C++14
50 / 100
154 ms10652 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define ll long long #define ld long double const int N=5e5+50,inf=1e9; int a[N],b[N],c[2*N]; pair<int,int>Qs[200050]; int main(){ int n;scanf("%i",&n); for(int i=1;i<=n;i++) scanf("%i",&a[i]); for(int i=1;i<=n;i++) scanf("%i",&b[i]),c[b[i]]=a[i]; int q;scanf("%i",&q); for(int i=1,l,r;i<=q;i++){scanf("%i%i",&l,&r);Qs[i]={l,r};} bool subtask5=true; for(int i=2;i<=n;i++) if(a[i-1]>a[i]||b[i-1]>b[i]) subtask5=false; if(!subtask5){ for(int I=1;I<=q;I++){ int l=Qs[I].fi,r=Qs[I].se; vector<int>A,B; for(int i=l;i<=r;i++) A.pb(a[i]),B.pb(b[i]); B.pb(inf); sort(A.begin(),A.end()),sort(B.begin(),B.end()); //for(auto i:A) printf("%i ",i);printf("\n"); //for(auto i:B) printf("%i ",i);printf("\n"); int m=A.size(); bool res=true; for(int i=m-1,j=m-1;i>=0;i--){ while(j>=0&&A[j]>B[i]) j--;j++; if(i<j||(i==j&&B[i+1]>c[B[i]])) res=false; //printf("%i: %i\n",i,j); } if(res) printf("Yes\n"); else printf("No\n"); } } else{ int pref[n+10]={0};for(int i=2;i<=n;i++){pref[i]=pref[i-1];if(a[i-1]<b[i]) pref[i]++;} for(int I=1;I<=q;I++){ int l=Qs[I].fi,r=Qs[I].se; if(pref[r]-pref[l]==0) printf("Yes\n"); else printf("No\n"); } } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:31:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   31 |     while(j>=0&&A[j]>B[i]) j--;j++;
      |     ^~~~~
Main.cpp:31:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   31 |     while(j>=0&&A[j]>B[i]) j--;j++;
      |                                ^
Main.cpp:12:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     int n;scanf("%i",&n);
      |           ~~~~~^~~~~~~~~
Main.cpp:13:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for(int i=1;i<=n;i++) scanf("%i",&a[i]);
      |                           ~~~~~^~~~~~~~~~~~
Main.cpp:14:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for(int i=1;i<=n;i++) scanf("%i",&b[i]),c[b[i]]=a[i];
      |                           ~~~~~^~~~~~~~~~~~
Main.cpp:15:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     int q;scanf("%i",&q);
      |           ~~~~~^~~~~~~~~
Main.cpp:16:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for(int i=1,l,r;i<=q;i++){scanf("%i%i",&l,&r);Qs[i]={l,r};}
      |                               ~~~~~^~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...