QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#834855 | #9865. Dolls | hos_lyric | RE | 0ms | 3732kb | C++14 | 3.1kb | 2024-12-28 04:51:59 | 2024-12-28 04:51:59 |
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")
// [0, n)
bool check(const vector<int> &as) {
const int n = as.size();
vector<int> mn(n + 2, -2), mx(n + 2, -2);
for (int i = 1; i <= n; ++i) mn[i] = mx[i] = as[i - 1];
vector<int> lef(n + 2), rig(n + 2);
for (int i = 0; i <= n + 1; ++i) {
lef[i] = i - 1;
rig[i] = i + 1;
}
queue<int> que;
auto visit = [&](int l) -> void {
const int r = rig[l];
if (mx[l] + 1 == mn[r] || mx[r] + 1 == mn[l]) {
que.push(l);
}
};
for (int i = 1; i < n; ++i) visit(i);
for (; que.size(); ) {
const int l = que.front();
que.pop();
const int r = rig[l];
const int ll = lef[l], rr = rig[r];
chmin(mn[l], mn[r]);
chmax(mx[l], mx[r]);
lef[l] = ll;
rig[l] = rr;
rig[ll] = lef[rr] = l;
visit(ll);
visit(l);
}
const bool ret = (rig[rig[0]] == n + 1);
// cerr<<"[check] "<<as<<": "<<ret<<endl;
return ret;
}
int N;
vector<int> A;
bool check(int l, int r) {
if (r > N) return false;
vector<pair<int, int>> ais;
for (int i = l; i < r; ++i) ais.emplace_back(A[i], i);
sort(ais.begin(), ais.end());
vector<int> bs;
for (const auto &ai : ais) bs.push_back(ai.second - l);
return check(bs);
}
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d", &N);
A.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &A[i]);
}
int ans = 0;
for (int i = 0; i < N; ) {
int lo = i + 1, hi = i + 2;
for (; check(i, hi); ) {
lo = hi;
hi = i + (hi - i) * 2;
}
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
(check(i, mid) ? lo : hi) = mid;
}
// cerr<<COLOR("33")<<i<<" "<<lo<<COLOR()<<endl;
++ans;
i = lo;
}
printf("%d\n", N - ans);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
input:
8 4 2 1 4 3 4 1 4 2 3 4 3 1 4 2 5 1 3 5 2 4 5 1 4 2 5 3 5 2 5 3 1 4 6 1 3 6 5 2 4 6 2 5 1 3 6 4
output:
3 3 2 3 3 3 4 4
result:
ok 8 numbers
Test #2:
score: -100
Runtime Error
input:
5913 1 1 2 1 2 2 2 1 3 1 2 3 3 1 3 2 3 2 1 3 3 2 3 1 3 3 1 2 3 3 2 1 4 1 2 3 4 4 1 2 4 3 4 1 3 2 4 4 1 3 4 2 4 1 4 2 3 4 1 4 3 2 4 2 1 3 4 4 2 1 4 3 4 2 3 1 4 4 2 3 4 1 4 2 4 1 3 4 2 4 3 1 4 3 1 2 4 4 3 1 4 2 4 3 2 1 4 4 3 2 4 1 4 3 4 1 2 4 3 4 2 1 4 4 1 2 3 4 4 1 3 2 4 4 2 1 3 4 4 2 3 1 4 4 3 1 2 4...