//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
struct node{
int s,e,m;
int val,lazy;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void propo(){
if (lazy){
val+=lazy;
if (s!=e){
l->lazy+=lazy;
r->lazy+=lazy;
}
lazy=0;
}
}
void update(int i,int j,int k){
if (s==i && e==j) lazy+=k;
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
l->propo(),r->propo();
val=min(l->val,r->val);
}
}
int query(int i,int j){
propo();
if (s==i && e==j) return val;
else if (j<=m) return l->query(i,j);
else if (m<i) return r->query(i,j);
else return min(l->query(i,m),r->query(m+1,j));
}
void clear(){
val=lazy=0;
if (s!=e){
l->clear();
r->clear();
}
}
} *root=new node(0,100005);
int n;
int pos[100005];
int type[100005];
int val[100005];
int ans[100005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TC;
cin>>TC;
while (TC--){
root->clear();
cin>>n;
rep(x,0,n) cin>>pos[x];
rep(x,0,n) cin>>type[x];
rep(x,0,n) cin>>val[x];
int last_pos;
rep(x,n,0){
last_pos=x;
if (type[x]==0) break;
}
rep(x,0,last_pos){
if (type[x]==0) root->update(val[x],100005,-1);
else root->update(val[x],100005,1);
ans[x]=-1;
}
int curr=-1;
multiset<int> s; //current processed what
rep(x,last_pos,n){
if (type[x]==0) root->update(val[x],100005,-1);
else root->update(val[x],100005,1);
while (root->query(0,100005)>=0 && curr<x){
curr++;
if (type[curr]==0){
s.insert(val[curr]);
}
else{
root->update(val[curr],100005,-1);
auto temp=s.lower_bound(val[curr]);
if (temp!=s.end()){
root->update(*temp,100005,1);
s.erase(temp);
}
}
}
//cout<<x<<" "<<curr<<endl;
if (curr==-1) ans[x]=-1;
else ans[x]=2*pos[x]-pos[curr];
}
rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
}
}
Compilation message
santa.cpp: In constructor 'node::node(int, int)':
santa.cpp:41:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
s=_s,e=_e,m=s+e>>1;
~^~
santa.cpp: In function 'int main()':
santa.cpp:19:26: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
^
santa.cpp:152:3: note: in expansion of macro 'rep'
rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
^~~
santa.cpp:152:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
rep(x,0,n) cout<<ans[x]<<" "; cout<<endl;
^~~~
santa.cpp:112:7: warning: 'last_pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
int last_pos;
^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
9728 KB |
Output is correct |
2 |
Correct |
21 ms |
9728 KB |
Output is correct |
3 |
Correct |
31 ms |
9984 KB |
Output is correct |
4 |
Correct |
45 ms |
10240 KB |
Output is correct |
5 |
Correct |
71 ms |
10872 KB |
Output is correct |
6 |
Correct |
105 ms |
11640 KB |
Output is correct |
7 |
Correct |
177 ms |
13512 KB |
Output is correct |
8 |
Correct |
269 ms |
15352 KB |
Output is correct |
9 |
Correct |
330 ms |
17784 KB |
Output is correct |
10 |
Correct |
474 ms |
20728 KB |
Output is correct |