fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. typedef long long ll;
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL); cout.tie(NULL);
  10.  
  11. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  12. int N = 2e5 + 5;
  13. vector<ll> v(N + 1);
  14. for(int i = 1; i<=N;i++) v[i] = rng();
  15. int n, q; cin>>n>>q;
  16. vector<ll> a(n);
  17. vector<ll> b(n);
  18. for(int i = 0; i<n;i++) cin>>a[i];
  19. for(int i = 0; i < n;i++) cin>>b[i];
  20.  
  21. vector<ll> prefa(n+1,0);
  22. vector<ll> prefb(n+1,0);
  23. for(int i = 1; i<n;i++) {
  24. prefa[i] = prefa[i-1] + v[a[i-1]];
  25. prefb[i] = prefb[i-1] + v[b[i-1]];
  26. }
  27. while(q--){
  28. int la,ra,lb,rb; cin>>la>>ra>>lb>>rb;
  29. ll vala = prefa[ra] - prefa[la - 1];
  30. ll valb = prefb[rb] - prefb[lb - 1];
  31. if(vala == valb) cout<<"Yes"<<endl;
  32. else cout<<"No"<<endl;
  33.  
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5324KB
stdin
5 4
1 2 3 2 4
2 3 1 4 2
1 3 1 3
1 2 3 5
1 4 2 5
1 5 1 5
stdout
Yes
No
No
Yes