QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#109442 | #6506. Chase Game 3 | wnmrmr# | WA | 40ms | 3476kb | C++23 | 1.7kb | 2023-05-29 01:33:35 | 2023-05-29 01:33:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define pb push_back
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
template <typename ND, typename T = typename ND::T>
struct SegIt {
int n;
vector<ND> t;
SegIt(int _n): n(_n), t(2*n) {}
SegIt(vector<T> &v): n(v.size()), t(2*n) {
for(int i=0;i<n;i++)
t[i+n] = ND(v[i]);
build();
}
void build() {
for(int i=n-1;i>0;i--)
t[i] = t[2*i] + t[2*i+1];
}
void update(int pos, T val) {
int p = pos + n ;
t[p] = ND(val);
while(p) {
p /= 2;
t[p] = t[2*p] + t[2*p+1];
}
}
ND query(int l, int r) {
ND tl, tr;
r++;
for(l += n, r += n; l < r; l /= 2, r/= 2) {
if(l&1) tl = tl + t[l++];
if(r&1) tr = t[--r] + tr;
}
return tl + tr;
}
};
struct Node {
using T = int;
T mn;
Node(): mn(numeric_limits<T>::max()) {}
Node(T x): mn(x) {}
friend Node operator+(Node lhs, Node rhs) {
return Node(min(lhs.mn, rhs.mn));
}
};
using Seg = SegIt<Node>;
const int INF = 1e9;
void solve() {
int n; cin >> n;
vector<int> p(n); for(int &x: p) cin >> x, x--;
vector<int> v(n, INF);
for(int i=0;i<n-1;i++) {
int a = p[i], b = p[i+1];
if(a > b) swap(a, b);
if(a + 1 == b) continue;
v[a] = min(v[a], b);
}
Seg seg(v);
for(int i=0;i<n;i++) {
int j = v[i];
if(j - i <= 2 || j == INF) continue;
if(seg.query(i, j-1).mn >= j) {
cout << "No" << '\n';
return;;
}
}
cout << "Yes" << '\n';
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int t; cin >> t;
while(t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3384kb
input:
5 2 1 2 3 2 3 1 4 1 4 3 2 5 1 5 2 3 4 6 1 2 3 4 5 6
output:
Yes Yes No No Yes
result:
ok 5 token(s): yes count is 3, no count is 2
Test #2:
score: 0
Accepted
time: 2ms
memory: 3476kb
input:
8 2 1 2 2 2 1 3 1 2 3 3 3 1 2 3 2 1 3 3 2 3 1 3 3 2 1 3 1 3 2
output:
Yes Yes Yes Yes Yes Yes Yes Yes
result:
ok 8 token(s): yes count is 8, no count is 0
Test #3:
score: -100
Wrong Answer
time: 40ms
memory: 3392kb
input:
100000 4 4 1 3 2 4 3 2 4 1 4 3 2 1 4 4 2 4 3 1 4 1 2 3 4 4 2 3 1 4 4 1 3 4 2 4 3 4 1 2 4 1 3 2 4 4 1 4 3 2 4 3 4 2 1 4 3 2 4 1 4 4 2 3 1 4 3 2 4 1 4 4 1 2 3 4 3 2 1 4 4 4 1 3 2 4 1 3 4 2 4 1 4 2 3 4 2 4 3 1 4 2 3 1 4 4 4 2 3 1 4 2 1 3 4 4 3 1 2 4 4 1 2 3 4 4 4 3 2 1 4 3 4 1 2 4 1 3 2 4 4 4 2 1 3 4 3...
output:
Yes No No Yes Yes Yes Yes No Yes No Yes No Yes No No No Yes Yes No Yes Yes Yes Yes Yes Yes Yes No Yes Yes No Yes Yes Yes No Yes No Yes Yes No No No Yes Yes Yes Yes Yes No Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No Y...
result:
wrong answer expected YES, found NO [2nd token]