# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
641059 |
2022-09-15T21:34:39 Z |
urosk |
Exam (eJOI20_exam) |
C++14 |
|
81 ms |
616 KB |
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 5005
ll n;
ll a[maxn],b[maxn],c[maxn],d[maxn];
pll p[maxn];
ll l[maxn],r[maxn];
ll t[4*maxn];
void upd(ll v,ll tl,ll tr,ll i,ll x){
if(tl==tr){t[v] = x;return;}
ll mid = (tl+tr)/2;
if(i<=mid) upd(2*v,tl,mid,i,x);
else upd(2*v+1,mid+1,tr,i,x);
t[v] = t[2*v] + t[2*v+1];
}
void init(ll v,ll tl,ll tr){
if(tl==tl){t[v] = (d[tl]==b[tl]);return;}
ll mid = (tl+tr)/2;
init(2*v,tl,mid); init(2*v+1,mid+1,tr);
t[v] = t[2*v] + t[2*v+1];
}
ll ans,cur;
void upd(ll i,ll x){
if(d[i]==b[i]) cur--;
d[i] = x;
if(d[i]==b[i]) cur++;
}
void tc(){
cin >> n;
for(ll i = 1;i<=n;i++) cin >> a[i];
for(ll i = 1;i<=n;i++) cin >> b[i];
for(ll i = 1;i<=n;i++) p[i] = {a[i],i};
stack<ll> s;
for(ll i = 1;i<=n;i++){
while(sz(s)&&a[i]>=a[s.top()]) s.pop();
if(!sz(s)) l[i] = 0;
else l[i] = s.top();
s.push(i);
}
while(sz(s)) s.pop();
for(ll i = n;i>=1;i--){
while(sz(s)&&a[i]>=a[s.top()]) s.pop();
if(!sz(s)) r[i] = n+1;
else r[i] = s.top();
s.push(i);
}
sort(p+1,p+n+1);
ans = 0;
for(ll j = 1;j<=n;j++){
ll x = p[j].fi;
ll i = p[j].sc;
ans = cur;
upd(i,x);
ll lmax = i,cntmax = cur;
ll lgr = l[i];
i--;
while(i>lgr){
upd(i,x);
if(cur>cntmax) cntmax = cur,lmax = i;
i--;
}
for(ll i = 1;i<=n;i++){
if(i<=p[j].sc&&i>=lmax) upd(i,x);
else upd(i,c[i]);
}
i = p[j].sc;
ll rmax = i;
cntmax = cur;
ll rgr = r[i];
i++;
while(i<rgr){
upd(i,x);
if(cur>cntmax) cntmax = cur,rmax = i;
i++;
}
for(ll i = 1;i<=n;i++){
if(i<=rmax&&i>=lmax) upd(i,x);
else upd(i,c[i]);
}
if(cur>ans){
for(ll i = 1;i<=n;i++) c[i] = d[i];
}else{
for(ll i = 1;i<=n;i++) d[i] = c[i];
}
}
cout<<cur<<endl;
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
Compilation message
exam.cpp: In function 'void init(long long int, long long int, long long int)':
exam.cpp:60:10: warning: self-comparison always evaluates to true [-Wtautological-compare]
60 | if(tl==tl){t[v] = (d[tl]==b[tl]);return;}
| ~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
616 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |