/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 1ms 544.0 KiB
#4 Time Exceeded ≥2086ms ≥2.094 MiB
#5 Time Exceeded ≥2089ms ≥10.41 MiB

Code

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--){
    int n, q;
    cin >> n;
    multiset<int> st1, st2;
    vector<ll> a(n), mn1(n), mn2(n), mx1(n), mx2(n), ans(n);
    for (int i = 0; i < n; i++){
      cin >> a[i];
      st1.insert(a[i]);
      auto it1 = st1.lower_bound(a[i]);
      auto it2 = st1.lower_bound(a[i] + 1);
      int x = distance(st1.begin(), it1);
      int y = (i + 1) - distance(st1.begin(), it2);
      mn1[i] = x;
      mx1[i] = y;
    }
    int c = 0;
    for (int i = n - 1; i >= 0; i--){
      c++;
      st2.insert(a[i]);
      auto it1 = st2.lower_bound(a[i]);
      auto it2 = st2.lower_bound(a[i] + 1);
      int x = distance(st2.begin(), it1);
      int y = c - distance(st2.begin(), it2);
      mn2[i] = x;
      mx2[i] = y;
    }
    for (int i = 0; i < n; i++){
      ans[i] = mn1[i] * mx2[i] + mn2[i] * mx1[i];
    }
    cin >> q;
    while (q--){
      int j;
      cin >> j;
      j--;
      cout << ans[j] << "\n";
    }
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:11:49
Judged At
2024-12-17 11:33:09
Judged By
Score
20
Total Time
≥2089ms
Peak Memory
≥10.41 MiB