Advertisement
BaoJIaoPisu

Untitled

Aug 6th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pb push_back
  5. #define pf push_front
  6. #define popb pop_back
  7. #define popf pop_front
  8. #define ins insert
  9. #define pq priority_queue
  10. #define minele min_element
  11. #define maxele max_element
  12. #define lb lower_bound //first pos >= val
  13. #define ub upper_bound // first pos > val
  14. #define cnt_bit __builtin_popcount
  15. #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  16. //#pragma GCC optimize("Ofast")
  17. //#pragma GCC target("avx,avx2,fma")
  18. using namespace std;
  19.  
  20. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  21.  
  22. typedef long long ll;
  23. typedef pair<ll, ll> pll;
  24. typedef pair<int, int> pii;
  25.  
  26.  
  27. int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
  28. int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  29. int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  30.  
  31. const ll oo = 1e18;
  32. const ll maxN = 1e6;
  33.  
  34. /* Author : Le Ngoc Bao Anh, 10A5, LQD High School for Gifted Student */
  35.  
  36. void maximize(int &a, int b) {
  37.     a = max(a, b);
  38. }
  39.  
  40. void minimize(int &a, int b) {
  41.     a = min(a, b);
  42. }
  43.  
  44. ll v[maxN], a[maxN], b[maxN];
  45. ll pref[maxN][2];
  46.  
  47. void solve() {
  48.     ll ans = 0, sum = 0;
  49.     int n; cin >> n;
  50.     for(int i = 1; i <= n; i++) cin >> a[i];
  51.     for(int i = 1; i <= n; i++) cin >> b[i];
  52.     for(int i = 1; i <= n; i++) {
  53.         ll x = rng() % oo; x++;
  54.         sum ^= x;
  55.         v[i] = x;
  56.     }
  57.  
  58.     for(int i = 1; i <= n; i++) pref[i][0] = pref[i - 1][0] ^ v[a[i]];
  59.     for(int i = 1; i <= n; i++) pref[i][1] = pref[i - 1][1] ^ v[b[i]];
  60.  
  61.     for(int i = 1; i <= n; i++) {
  62.         for(int j = i; j <= n; j++) {
  63.             ll x = pref[n][1] ^ pref[j][1];
  64.             x = x ^ pref[i - 1][1];
  65.             x = x ^ pref[j][0] ^ pref[i - 1][0];
  66.             if(x == sum) {
  67.                 ans++;
  68.                 continue;
  69.             }
  70.  
  71.             x = pref[n][0] ^ pref[j][0];
  72.             x = x ^ pref[i - 1][0];
  73.             x = x ^ pref[j][1] ^ pref[i - 1][1];
  74.             if(x == sum) {
  75.                 ans++;
  76.             }
  77.         }
  78.     }
  79.  
  80.     cout << ans;
  81. }
  82.  
  83. int main()
  84. {
  85.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  86.     #ifndef ONLINE_JUDGE
  87.     freopen("input.txt", "r", stdin);
  88.     freopen("output.txt", "w", stdout);
  89.     #else
  90.     //online
  91.     #endif
  92.  
  93.     int tc = 1, ddd = 0;
  94.     // cin >> tc;
  95.     while(tc--) {
  96.         //ddd++;
  97.         //cout << "Case #" << ddd << ": ";
  98.         solve();
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement