This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
void answer(vector<int> C, vector<int> X, vector<int> Y);
int n, m;
vector<int> a, b;
vector<int> x, y;
void build(int p, int l, int r) {
if (l == r-1) {
if (b[l] <= n) {
x[p-1] = a[b[l]];
}
else x[p-1] = -1;
if (b[r] <= n) {
y[p-1] = a[b[r]];
}
else y[p-1] = -1;
}
else {
x[p-1] = -(2*p);
y[p-1] = -(2*p+1);
int mid = (l+r)/2;
build(2*p, l, mid);
build(2*p+1, mid+1, r);
if (x[2*p-1] == -1 && y[2*p-1] == -1) {
x[p-1] = -1;
x[2*p-1] = 1012345678; //flag for it to be deleted
y[2*p-1] = 1012345678; //flag for it to be deleted
}
if (x[2*p] == -1 && y[2*p] == -1) {
y[p-1] = -1;
x[2*p] = 1012345678; //flag for it to be deleted
y[2*p] = 1012345678; //flag for it to be deleted
}
}
}
void create_circuit(int M, vector<int> A) {
a = A; m = M;
n = A.size();
b.push_back(0);
a.push_back(0);
while (b.size() < n+1) {
vector<int> temp;
for (int i = 0; i < b.size(); i++) {
temp.push_back(b[i]);
temp.push_back(b[i] + b.size());
}
b = temp;
}
for (int i = 0; i < b.size() - a.size(); i++) {
b[i] = 1012345678;
}
vector<int> temp = b;
sort(temp.begin(), temp.end());
vector<int> re;
re.resize(temp.size()+1);
for (int i = 0; i< temp.size(); i++) {
if (temp[i] != 1012345678) {
re[temp[i]] = i;
}
else break;
}
for (int i = 0; i < b.size(); i++) {
if (b[i] != 1012345678) b[i] = re[b[i]];
}
/*for (int i = 0; i < b.size(); i++) {
printf("%d ", b[i]);
}
printf("\n");
for (int i = 0; i < a.size(); i++) {
printf("%d ", a[i]);
}
printf("\n");*/
vector<int> C(M + 1);
for (int i = 0; i <= m; i++) {
C[i] = -1;
}
x.resize(b.size()-1); y.resize(b.size()-1);
build(1, 0, b.size()-1);
re.clear();
re.resize(b.size());
int cnt = -1;
for (int i = 0; i < x.size(); i++) {
if (x[i] != 1012345678) {
re[i] = cnt;
cnt--;
}
}
vector<int> X, Y;
for (int i = 0; i < x.size(); i++) {
if (x[i] == 1012345678) continue;
if (x[i] < 0) X.push_back(re[-x[i]-1]);
else X.push_back(x[i]);
if (y[i] < 0) Y.push_back(re[-y[i]-1]);
else Y.push_back(y[i]);
}
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:46:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | while (b.size() < n+1) {
| ~~~~~~~~~^~~~~
doll.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < b.size(); i++) {
| ~~^~~~~~~~~~
doll.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 0; i < b.size() - a.size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~
doll.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i< temp.size(); i++) {
| ~^~~~~~~~~~~~~
doll.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < b.size(); i++) {
| ~~^~~~~~~~~~
doll.cpp:87:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int i = 0; i < x.size(); i++) {
| ~~^~~~~~~~~~
doll.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int i = 0; i < x.size(); i++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |