답안 #753726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753726 2023-06-05T18:41:44 Z emad234 Exam (eJOI20_exam) C++17
14 / 100
1000 ms 5804 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mxN = 2e6 + 1;
const ll mod = 1e9 + 7;
ll a[mxN],b[mxN];
bool tk[mxN];
signed main()
{
  ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
  ll n;
  cin >>n;
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>q;
  for(ll i = 0;i < n;i++) cin >>a[i];
  for(ll i = 0;i < n;i++) {
    cin >>b[i];
    q.push({b[i],i});
    q.push({b[i],n + (n - i)});
  }
  ll bf = -1;
  ll l = n,r = n;
  ll diff = 0;
  ll ans = 0;
  while(q.size()){
    pair<ll,ll> u = q.top();
    q.pop();
    for(ll i = l;i <= r;i++){
      ans -= tk[i];
      tk[i] = 0;
      if(b[i] == bf){
        ans++;
        tk[i] = 1;
      }
    }
    // cout<<l<<' '<<r<<' '<<ans<<'\n';
    // cout<<u.first<<' '<<u.second<<'\n';
    l = n;r = n;
    diff = 0;
    ll num = 0;
    ll mx = 0;
    if(u.second < n){
      for(ll i = u.second;i >= 0;i--){
        mx = max(mx,a[i]);
        num += (b[i] == u.first);
        num -= tk[i];
        if(mx == u.first){
          if(num > diff){
            r = u.second;
            l = i;
            diff = num;
          }
        }
      }
    }else{
      u.second = abs(u.second - 2 * n);
      for(ll i = u.second;i < n;i++){
        mx = max(mx,a[i]);
        num += (b[i] == u.first);
        num -= tk[i];
        if(mx == u.first){
          if(num > diff){
            r = i;
            l = u.second;
            diff = num;
          }
        }
      }
    }
    bf = u.first;
  }
  for(ll i = l;i <= r;i++){
    ans -= tk[i];
    tk[i] = 0;
    if(b[i] == bf){
      ans++;
      tk[i] = 1;
    }
  }
  // cout<<l<<' '<<r<<' '<<ans<<'\n';

  cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 676 ms 1748 KB Output is correct
3 Execution timed out 1084 ms 5804 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 724 KB Output is correct
2 Execution timed out 1075 ms 3024 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -