# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
654762 |
2022-11-01T14:16:40 Z |
Antekb |
Matching (CEOI11_mat) |
C++14 |
|
2000 ms |
65536 KB |
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
using namespace std;
///~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename H, typename T>
ostream& operator<<(ostream& os, pair<H, T> m){
return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H>
ostream& operator<<(ostream& os, vector<H> V){
os<<"{";
for(int i=0; i<V.size(); i++){
if(i)os<<" ";
os<<V[i];
}
os<<"}";
return os;
}
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
///~~~~~~~~~~~~~~~~~~~~~~~~~
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=2e6+5, INF=1e9+5, mod=1e9+7;
int co[N], co2[N], pref[N];
int main(){
//BOOST;
int n, m;
cin>>n>>m;
vi V(n), V3(n), V2;
for(int &i:V3)cin>>i;
for(int i=0; i<n; i++){
V[V3[i]-1]=i+1;
}
//for(int i:V)cout<<i<<" ";
set<pii> S, S2;
S.insert({0, -1});
S2.insert({n+1, -1});
for(int i=0; i<n; i++){
co[i]=S.upper_bound(mp(-V[i], i))->nd;
S.insert(mp(-V[i], i));
//deb(co[i], co2[i]);
}
S.clear();
for(int i=0; i<n; i++){
co2[i]=S2.upper_bound(mp(V[i], i))->nd;
S2.insert(mp(V[i], i));
}
S2.clear();
for(int i:V)V2.pb(i);
V.clear();
for(int i=0; i<m; i++){
int x;
cin>>x;
V2.pb(x);
}
vi ans;
for(int i=2; i<n+m; i++){
pref[i]=pref[i-1];
while(pref[i]){
if(pref[i]!=n-1 && (co[pref[i]+1]==-1 || V2[i]>V2[i-pref[i]-1+co[pref[i]+1]])
&& (co2[pref[i]+1]==-1 || V2[i]<V2[i-pref[i]-1+co2[pref[i]+1]])){
break;
}
pref[i]=pref[pref[i]];
}
if(pref[i]!=n-1 && (co[pref[i]+1]==-1 || V2[i]>V2[i-pref[i]-1+co[pref[i]+1]])
&& (co2[pref[i]+1]==-1 || V2[i]<V2[i-pref[i]-1+co2[pref[i]+1]])){
pref[i]++;
}
//deb(i-n, pref[i]);
if(pref[i]==n-1 && i-n>=n-1){
ans.pb(i-n-n+2);
}
}
cout<<ans.size()<<"\n";
for(int i:ans)cout<<i<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
852 KB |
Output is correct |
2 |
Correct |
8 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
880 KB |
Output is correct |
2 |
Correct |
9 ms |
852 KB |
Output is correct |
3 |
Correct |
2 ms |
392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
4636 KB |
Output is correct |
2 |
Correct |
60 ms |
3172 KB |
Output is correct |
3 |
Correct |
133 ms |
6396 KB |
Output is correct |
4 |
Correct |
125 ms |
6392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
4520 KB |
Output is correct |
2 |
Correct |
84 ms |
3152 KB |
Output is correct |
3 |
Correct |
88 ms |
4292 KB |
Output is correct |
4 |
Correct |
70 ms |
5064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
4592 KB |
Output is correct |
2 |
Correct |
89 ms |
5096 KB |
Output is correct |
3 |
Correct |
92 ms |
4828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
578 ms |
25072 KB |
Output is correct |
2 |
Execution timed out |
2073 ms |
65536 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
29960 KB |
Output is correct |
2 |
Correct |
288 ms |
9248 KB |
Output is correct |
3 |
Execution timed out |
2081 ms |
65536 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
12348 KB |
Output is correct |
2 |
Correct |
367 ms |
20356 KB |
Output is correct |
3 |
Correct |
447 ms |
14672 KB |
Output is correct |
4 |
Runtime error |
1053 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
397 ms |
15936 KB |
Output is correct |
2 |
Correct |
429 ms |
14156 KB |
Output is correct |
3 |
Correct |
220 ms |
12300 KB |
Output is correct |
4 |
Correct |
1442 ms |
65536 KB |
Output is correct |