Submission #1062074

#TimeUsernameProblemLanguageResultExecution timeMemory
1062074Jarif_RahmanFlooding Wall (BOI24_wall)C++17
0 / 100
4 ms4188 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll md = 1e9+7; const int N = 5e5+5; ll pw2[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); pw2[0] = 1; for(int i = 1; i < N; i++) pw2[i] = (pw2[i-1]*2)%md; int n; cin >> n; vector<int> A(n), B(n); int m = 0; for(int &x: A) cin >> x, m = max(m, x); for(int &x: B) cin >> x, m = max(m, x); for(int i = 0; i < n; i++) if(A[i] > B[i]) swap(A[i], B[i]); m++; vector<int> cmn(m, 0), cmx(m, 0); for(int i = 0; i < n; i++) cmn[A[i]]++, cmx[B[i]]++; ll ans = 0; for(int i = 0; i+1 < n; i++){ cmn[A[i]]--, cmx[B[i]]--; int x = 0, y = 0; for(int j = m-1; j > B[i]; j--) x+=cmn[j], y+=cmx[j]; for(int j = B[i]; j > A[i]; j--){ x+=cmn[j], y+=cmx[j]; if(x > 0) ans+=pw2[n-1], ans%=md; else if(y > 0) ans+=(pw2[n-1-y]*(pw2[y]-1))%md, ans%=md; } for(int j = A[i]; j >= 1; j--){ x+=cmn[j], y+=cmx[j]; if(x > 0) ans+=pw2[n], ans%=md; else if(y > 0) ans+=(pw2[n-y]*(pw2[y]-1))%md, ans%=md; } } /*ans+=((A[0]+B[0])*pw2[n-1])%md; for(int i = 1; i < n; i++){ if(A[i] > A[i-1]) ans+=((A[i]-A[i-1])*pw2[n-2])%md, ans%=md; if(B[i] > A[i-1]) ans+=((B[i]-A[i-1])*pw2[n-2])%md, ans%=md; if(A[i] > B[i-1]) ans+=((A[i]-B[i-1])*pw2[n-2])%md, ans%=md; if(B[i] > B[i-1]) ans+=((B[i]-B[i-1])*pw2[n-2])%md, ans%=md; }*/ /*for(int i = 0; i < n; i++) ans-=((A[i]+B[i])*pw2[n-1])%md, ans%=md; if(ans < 0) ans+=md;*/ cout << ans << "\n"; }
#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...