# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
274411 | AKaan37 | Santa Claus (RMI19_santa) | C++17 | 1100 ms | 4216 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 300000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 100005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,c[li],mx,vis[li],dp[li];
int cev;
string s;
vector<int> v;
inline int naivesol(int x){
if(x<mx)return -1;
int bas=1;
int son=x;
while(bas<=son){
multiset<int> st;
FOR{
if(b[i]==0)st.insert(c[i]);
else{
if(i<ort){
auto it=st.lower_bound(c[i]);
if(it!=st.end())st.erase(it);
}
}
}
for(int i=ort;i<=x;i++){
if(b[i]==0)continue;
auto it=st.lower_bound(c[i]);
if(it!=st.end())st.erase(it);
}
if(st.size()==0)bas=ort+1;
else son=ort-1;
}
if(son<1)return -1;
return a[x]+(a[x]-a[son]);
}
main(void){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
FOR scanf("%lld",&a[i]);
FOR scanf("%lld",&b[i]);
FOR scanf("%lld",&c[i]);
mx=0;
FOR{
if(b[i]==0)mx=max(mx,i);
}
//~ dp[n]=naivesol(n);
FOR dp[i]=naivesol(i);
FOR printf("%lld ",dp[i]);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |