Time Exceeded
Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);
void sir() {
int N;
cin >> N;
vector<int> A(N + 1);
for (int i = 1; i <= N; i++) {
cin >> A[i];
}
int q;
cin >> q;
while (q--) {
int X;
cin >> X;
int ax = A[X];
int cL = 0;
int cG = 0;
for (int i = 1; i < X; i++) {
if (A[i] < ax) {
cL++;
}
}
for (int j = X + 1; j <= N; j++) {
if (A[j] > ax) {
cG++;
}
}
int c1 = cL * cG;
cL = 0;
cG = 0;
for (int i = 1; i < X; i++) {
if (A[i] > ax) {
cL++;
}
}
for (int j = X + 1; j <= N; j++) {
if (A[j] < ax) {
cG++;
}
}
int c2 = cL * cG;
cout << c1 + c2 << '\n';
}
}
int main() {
ALLAHU_AKBAR
ll t = 1;
cin >> t;
while (t--) {
sir();
}
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:58:02
- Judged At
- 2024-11-11 02:45:18
- Judged By
- Score
- 20
- Total Time
- ≥2088ms
- Peak Memory
- ≥1.312 MiB