QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#334078 | #8050. Random Permutation | hos_lyric | WA | 0ms | 4060kb | C++14 | 2.3kb | 2024-02-21 06:10:43 | 2024-02-21 06:10:44 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
// ?
const int M = 1000;
int N;
vector<int> P;
int main() {
for (; ~scanf("%d", &N); ) {
P.assign(N + 2, 0);
for (int i = 1; i <= N; ++i) {
scanf("%d", &P[i]);
}
vector<int> invP(N + 2, 0);
for (int i = 1; i <= N; ++i) invP[P[i]] = i;
vector<char> ss(N, +1);
Int ans = 0;
vector<int> freq(2 * M + 3, 0);
for (int a = 1; a <= N; ++a) {
const int i = invP[a];
ss[i] = -1;
fill(freq.begin(), freq.begin() + (2 * M + 3), 0);
int now = M + 1;
++freq[now];
for (int j = i - 1; j >= 1; --j) {
now += ss[j];
if (!(1 <= now && now <= 2 * M + 1)) break;
++freq[now];
}
Int here = 0;
now = M + 1;
here += (freq[2 * M + 2 - now] + freq[2 * M + 3 - now]);
for (int j = i + 1; j <= N; ++j) {
now += ss[j];
if (!(1 <= now && now <= 2 * M + 1)) break;
here += (freq[2 * M + 2 - now] + freq[2 * M + 3 - now]);
}
// cerr<<a<<": "<<here<<endl;
ans += here * a;
}
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4060kb
input:
4 1 4 2 3
output:
24
result:
wrong answer 1st numbers differ - expected: '22', found: '24'