Advertisement
SorahISA

[PCCA 2020 pC]

Feb 13th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  7.  
  8. const int maxn = 1 << 18;
  9.  
  10. vector<int> seg(2*maxn);
  11.  
  12. void build(vector<int> a, int len) {
  13.     for (int i = 0; i < len; ++i) {
  14.         seg[maxn + i] = a[i];
  15.     }
  16.     for (int i = maxn-1; i >= 1; --i) {
  17.         seg[i] = max(seg[i<<1], seg[i<<1|1]);
  18.     }
  19. }
  20.  
  21. int RMax(int L, int R, int now = 1, int nL = 0, int nR = maxn-1) {
  22.     if (L > nR or R < nL) return 0;
  23.     if (nR <= R and nL >= L) return seg[now];
  24.     return max(RMax(L, R, now*2  ,  nL        , (nL+nR)/2),
  25.                RMax(L, R, now*2+1, (nL+nR)/2+1,  nR      ));
  26. }
  27.  
  28. int32_t main() {
  29.     fastIO();
  30.    
  31.     int n, m, ans(0);
  32.     cin >> n >> m;
  33.    
  34.     vector<int> a(n), b(m), Ans;
  35.     vector<bool> now(n, 1);
  36.     for (auto &x : a) cin >> x;
  37.     for (auto &x : b) cin >> x, now[--x] = 0;
  38.     reverse(b.begin(), b.end());
  39.    
  40.     build(a, n);
  41.    
  42.     map<int, int> LtoR, RtoL;
  43.     int nL = 0, nR;
  44.     for (int i = 0; i < n; ++i) {
  45.         while (i < n and now[i]) ++i;
  46.         nR = i - 1;
  47.         // cout << nL << ", " << nR << "\n";
  48.         if (nL <= nR) LtoR[nL] = nR, RtoL[nR] = nL;
  49.         nL = i + 1;
  50.     }
  51.    
  52.     for (auto x : LtoR) {
  53.         ans = max(ans, (x.second-x.first+1) * RMax(x.first, x.second));
  54.     }
  55.    
  56.     int Lnum, Rnum;
  57.     for (auto x : b) {
  58.         Ans.push_back(ans);
  59.         if (x == 0 and now[1]) {
  60.             Lnum = 0;
  61.             Rnum = LtoR[1];
  62.             LtoR[Lnum] = Rnum;
  63.             RtoL[Rnum] = Lnum;
  64.         }
  65.         else if (x == n - 1 and now[n - 2]) {
  66.             Lnum = RtoL[n - 2];
  67.             Rnum = n - 1;
  68.             LtoR[Lnum] = Rnum;
  69.             RtoL[Rnum] = Lnum;
  70.         }
  71.         else if ((x == 0 or x == n - 1) or (!now[x - 1] and !now[x + 1])) {
  72.             Lnum = x;
  73.             Rnum = x;
  74.             LtoR[x] = x;
  75.             RtoL[x] = x;
  76.         }
  77.         else if (now[x - 1] and now[x + 1]) {
  78.             Lnum = RtoL[x - 1];
  79.             Rnum = LtoR[x + 1];
  80.             LtoR[Lnum] = Rnum;
  81.             RtoL[Rnum] = Lnum;
  82.         }
  83.         else if (now[x - 1]) {
  84.             Lnum = RtoL[x - 1];
  85.             Rnum = x;
  86.             LtoR[Lnum] = Rnum;
  87.             RtoL[Rnum] = Lnum;
  88.         }
  89.         else {
  90.             Lnum = x;
  91.             Rnum = LtoR[x + 1];
  92.             LtoR[Lnum] = Rnum;
  93.             RtoL[Rnum] = Lnum;
  94.         }
  95.         ans = max(ans, (Rnum-Lnum+1) * RMax(Lnum, Rnum));
  96.         now[x] = 1;
  97.     }
  98.    
  99.     reverse(Ans.begin(), Ans.end());
  100.     for (auto x : Ans) cout << x << "\n";
  101.    
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement