-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path323-game-on-permutation.cpp
More file actions
60 lines (57 loc) · 1.48 KB
/
Copy path323-game-on-permutation.cpp
File metadata and controls
60 lines (57 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Game on Permutation [1860C]
* Problem: https://codeforces.com/problemset/problem/1860/C
* Verdict: ACCEPTED Solved: 2025-03-10
* Language: C++17 (GCC 7-32)
* Runtime: 312 ms Memory: 4700 KB
* Tags: data structures, dp, games, greedy
* Author: BidoTeima
* Source: https://codeforces.com/contest/1860/submission/309886614
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 3;
int st[N<<2];
void update(int i, int x, int l, int r, int node){
if(i < l || i > r) return;
if(l==r){
st[node]=x;
return;
}
int mid = (l + r) >> 1;
update(i,x,l,mid,2*node+1),update(i,x,mid+1,r,2*node+2);
st[node]=max(st[2*node+1],st[2*node+2]);
}
int query(int ql, int qr, int l, int r, int node){
if(r < ql || l > qr) return 0;
if(ql <= l && r <= qr){
return st[node];
}
int mid = (l + r) >> 1;
return max(query(ql,qr,l,mid,2*node+1),query(ql,qr,mid+1,r,2*node+2));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i = 0; i <= ((n+2)<<2); i++)st[i]=0;
int a[n];
bool good[n+1]{};
multiset<int>ms;
int ans = 0;
for(int i = 0; i < n; i++){
cin>>a[i];
int best=query(1,a[i],1,n,0);
ans+=(best==1);
update(a[i],best+1,1,n,0);
}
cout<<ans<<'\n';
}
return 0;
}