C
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
#define x first
#define y second
//vector<vector<int>>adj(N);
int a[N], b[N];
void solve()
{
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i ++) cin >> a[i], b[i] = a[i];
sort(a + 1, a + n + 1);
int l = 1, r = n;
while(l <= n && a[l] == b[l]) l ++;
while(r >= 1 && a[r] == b[r]) r --;
if(r - l + 1 <= k) cout << "Yes";
else cout << "No";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
//cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
return 0;
}
D
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
#define x first
#define y second
//vector<vector<int>>adj(N);
int a[N];
void solve()
{
int n, q;
cin >> n >> q;
vector<vector<PII>> seg(q + 1);
for(int i = 1; i <= q; i ++) {
int l, r, x;
cin >> l >> r >> x;
seg[x].push_back({l, r});
}
for(int i = 1; i <= q; i ++) {
sort(seg[i].begin(), seg[i].end(),[&](PII a, PII b){
return a.first < b.first;
});
seg[i].push_back({n + 1, n + 1});
int L = 0, R = 0;
for(auto [l, r] : seg[i]) {
if(l > R) {
a[L]++;
a[R + 1]--;
L = l;
}
R = max(r, R);
}
}
for(int i = 1; i <= n; i ++) {
a[i] += a[i - 1];
cout << a[i] << " ";
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
//cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
return 0;
}
E
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
#define x first
#define y second
vector<vector<PII>>adj(N);
vector<vector<PII>>adj2(N);
int cnt;
int low[N], num[N], dfn;
int sccno[N];
stack<int> sta;
void dfs(int u) {
sta.push(u);
low[u] = num[u] = ++ dfn;
for(auto [v, w] : adj[u]) {
if(!num[v]) {
dfs(v);
low[u] = min(low[v], low[u]);
} else if(!sccno[v]) {
low[u] = min(low[u], num[v]);
}
}
if(low[u] == num[u]) {
cnt ++;
while(1) {
int v = sta.top(); sta.pop();
sccno[v] = cnt;
if(u == v) break;
}
}
}
void Tarjan(int n) {
cnt = dfn = 0;
for(int i = 1; i <= n; i ++) {
if(!num[i]) dfs(i);
}
}
struct edg{
int u, v, w;
} e[N];
int d[N];
int ans[N];
void solve()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i ++) {
int u, v, w;
cin >> w >> u >> v;
adj[u].push_back({v, w});
e[i] = {u, v, w};
}
Tarjan(n);
for(int i = 1; i <= m; i ++) {
auto [u, v, w] = e[i];
u = sccno[u], v = sccno[v];
if(u == v && w == 1) {
cout << "No\n";
return;
}
if(u != v) {
adj2[u].push_back({v, w});
d[v] ++;
// cout << u << " " << v << " " << w << endl;
}
}
cout << "Yes\n";
queue<int> q;
for(int i = 1; i <= cnt; i ++) {
if(d[i] == 0) q.push(i), ans[i] = 1;
}
while(q.size()) {
auto u = q.front(); q.pop();
for(auto [v, w] : adj2[u]) {
ans[v] = max(ans[v], ans[u] + w);
-- d[v];
if(d[v] == 0) q.push(v);
}
}
for(int i = 1; i <= n; i ++) {
cout << ans[sccno[i]] << " ";
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
//cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
return 0;
}
F
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF = 0x3f3f3f3f;
const ll INFll = 0x3f3f3f3f3f3f3f3f;
#define endl "\n"
#define x first
#define y second
//vector<vector<int>>adj(N);
int a[N];
void solve()
{
int n;
cin >> n;
stack<int> s;
ll ans = 1;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
while(s.size() && a[s.top()] < a[i]) {
s.pop();
}
if(i != 1) {
int cnt = i - 1;
if(s.size() ) {
// cout << i << " " << s.top() << endl;
cnt = min(cnt, i - s.top());
}
ans *= cnt;
// cout << cnt << endl;
}
s.push(i);
ans %= mod;
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cout << setprecision(11) << fixed;
int t;t=1;
//cin>>t;
for(int i=1;i<=t;i++){
//printf("Case %d: ",i);
solve();
}
return 0;
}