#include <bits/stdc++.h>
//#include <vector>
//#include <iostream>
#define int long long
#define ll long long
#define pb push_back
#define s second
#define f first
using namespace std;
const int N = 1000005;
int a[N],b[N];
vector <int> l[N],r[N];
vector <int> comp(vector <int> a,vector <int> b){
if (a.size() > b.size()) return a;
if (a.size() < b.size()) return b;
for (int i=0;i<a.size();i++){
if (a[i] > b[i]) return a;
if (a[i] < b[i]) return b;
}
return a;
}
vector <int> dfs(int x){
vector<int> mx;
if (a[x] < 0 && b[x] < 0) {
if ((-a[x]) > (-b[x])) mx = l[x];
else mx=r[x];
}else if (a[x] < 0){
mx = comp(l[x],dfs(b[x]));
}else if (b[x]<0){
mx = comp(r[x],dfs(a[x]));
}else{
mx= comp(dfs(a[x]),dfs(b[x]));
}
mx.pb(0);
return mx;
}
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for(int i = 1; i <= n; i++)
cin>>a[i]>>b[i];
for(int i = 1; i <= n; i++){
if(a[i]<0){
bool z=0;
for (int j=30;j>=0;j--){
if((1LL<<j)&(-a[i])) l[i].pb(1),z=1;
else if (z) l[i].pb(0);
}
}
if(b[i]<0){
bool z=0;
for (int j=30;j>=0;j--){
if((1LL<<j)&(-b[i])) r[i].pb(1),z=1;
else if (z) r[i].pb(0);
}
}
}
vector<int> res = dfs(1);
bool z=0;
for (int i=0;i<res.size();i++){
if (res[i] == 1) z=1;
if (z) cout<<res[i];
}
}
Compilation message
poklon.cpp: In function 'std::vector<long long int> comp(std::vector<long long int>, std::vector<long long int>)':
poklon.cpp:19:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i=0;i<a.size();i++){
| ~^~~~~~~~~
poklon.cpp: In function 'int main()':
poklon.cpp:65:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i=0;i<res.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47304 KB |
Output is correct |
2 |
Correct |
24 ms |
47292 KB |
Output is correct |
3 |
Correct |
24 ms |
47188 KB |
Output is correct |
4 |
Correct |
24 ms |
47188 KB |
Output is correct |
5 |
Correct |
25 ms |
47288 KB |
Output is correct |
6 |
Correct |
23 ms |
47212 KB |
Output is correct |
7 |
Correct |
24 ms |
47316 KB |
Output is correct |
8 |
Correct |
25 ms |
47380 KB |
Output is correct |
9 |
Correct |
24 ms |
47420 KB |
Output is correct |
10 |
Correct |
24 ms |
47608 KB |
Output is correct |
11 |
Correct |
45 ms |
51196 KB |
Output is correct |
12 |
Correct |
45 ms |
51688 KB |
Output is correct |
13 |
Correct |
80 ms |
67776 KB |
Output is correct |
14 |
Correct |
118 ms |
88524 KB |
Output is correct |
15 |
Correct |
122 ms |
75504 KB |
Output is correct |
16 |
Correct |
381 ms |
177056 KB |
Output is correct |
17 |
Runtime error |
545 ms |
262144 KB |
Execution killed with signal 9 |
18 |
Runtime error |
549 ms |
262144 KB |
Execution killed with signal 9 |
19 |
Runtime error |
659 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Runtime error |
559 ms |
262144 KB |
Execution killed with signal 9 |