/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 1ms 400.0 KiB
#3 Wrong Answer 1ms 324.0 KiB

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;
    set<int> st1, st2;
    map<int, int> mp1, mp2;
    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]);
      mp1[a[i]]++;
      int x = distance(st1.begin(), st1.lower_bound(a[i]));
      mn1[i] = x;
      mx1[i] = (i + 1) - x - mp1[a[i]];
    }
    int cnt = 0;
    for (int i = n - 1; i >= 0; i--){
      st2.insert(a[i]);
      mp2[a[i]]++;
      cnt++;
      int x = distance(st2.begin(), st2.lower_bound(a[i]));
      mn2[i] = x;
      mx2[i] = cnt - x - mp2[a[i]];
    }
    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:40:09
Judged At
2024-11-11 02:45:50
Judged By
Score
4
Total Time
1ms
Peak Memory
400.0 KiB