이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
const int N = (int)2e5 + 5;
const ll mod = (int)1e9 + 7;
const ll inf = (int)(1e9) + 100;
map<int, int> ma;
int cnt[N], n, a[N];
bool cs3 = 1;
void sub3() {
map<int, int> CNT;
ll pref = 0, ans = 0;
CNT[0]++;
for (int i = 1; i <= n; i++) {
if (a[i] == 2) pref += 1;
else pref -= 1;
ans += CNT[pref];
CNT[pref]++;
}
cout << (n * 1LL * (n + 1)) / 2 - ans;
}
void solve() {
cin >> n;
vector<int> v;
for (int i = 1; i <= n; i++) {
cin >> a[i];
v.pb(a[i]);
if (a[i] > 2) cs3 = 0;
}
sort(all(v));
v.erase(unique(all(v)), v.end());
int timer = 0;
for (auto i : v) {
ma[i] = ++timer;
}
if (cs3) {
sub3();
return;
}
for (int i = 1; i <= n; i++) a[i] = ma[a[i]];
if (n <= 2000) {
int ans = 0;
for (int i = 1; i <= n; i++) {
int mx = 0;
for (int j = 1; j <= n; j++) {
cnt[j] = 0;
}
for (int j = i; j <= n; j++) {
cnt[a[j]]++;
mx = max(mx, cnt[a[j]]);
if (mx >= (j - i + 1) / 2 + 1) ans++;
}
}
cout << ans;
return;
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
//cin >> T;
while (T--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |