# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
522690 | Be_dos | Odd-even (IZhO11_oddeven) | C++17 | 2 ms | 332 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.
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <random>
#include <cfloat>
#include <chrono>
#include <bitset>
#include <complex>
#include <immintrin.h>
#include <cassert>
#define BASE 1000
struct BigInt {
int32_t data[100];
BigInt() {
for(int32_t i = 0; i < 100; i++)
data[i] = 0;
}
BigInt(std::string str) {
for(int32_t i = 0; i < 100; i++)
data[i] = 0;
int32_t next = 0;
int32_t mult = 1;
for(int32_t i = str.size() - 1; i >= 0; i--) {
data[next] += (str[i] - '0') * mult;
mult *= 10;
if(mult == BASE) {
mult = 1;
next++;
}
}
}
BigInt operator+(int32_t x) {
BigInt res = *this;
res.data[0] += x;
for(int32_t i = 0; i < 100; i++) {
if(res.data[i] < BASE)
return res;
res.data[i] = 0;
res.data[i + 1]++;
}
}
BigInt operator-(int32_t x) {
BigInt res = *this;
res.data[0] -= x;
for(int32_t i = 0; i < 100; i++) {
if(res.data[i] >= 0)
return res;
res.data[i] += BASE;
res.data[i + 1]--;
}
}
BigInt operator+(BigInt other) {
BigInt res;
for(int32_t i = 0; i < 100; i++)
res.data[i] = data[i] + other.data[i];
for(int32_t i = 0; i < 99; i++) {
res.data[i + 1] += res.data[i] / BASE;
res.data[i] %= BASE;
}
return res;
}
BigInt operator-(BigInt other) {
BigInt res;
for(int32_t i = 0; i < 100; i++)
res.data[i] = data[i] - other.data[i];
for(int32_t i = 0; i < 99; i++) {
if(res.data[i] < 0) {
res.data[i] += BASE;
res.data[i + 1]--;
}
}
return res;
}
BigInt operator*(BigInt other) {
BigInt res;
for(int32_t i = 0; i < 50; i++)
for(int32_t j = 0; j < 50; j++)
res.data[i + j] += data[i] * other.data[j];
for(int32_t i = 0; i < 99; i++) {
res.data[i + 1] += res.data[i] / BASE;
res.data[i] %= BASE;
}
return res;
}
BigInt half() {
BigInt res;
for(int32_t i = 99; i >= 0; i--) {
res.data[i] += data[i] / 2;
if(i > 0)
res.data[i - 1] += (data[i] % 2) * (BASE / 2);
}
return res;
}
void output() {
bool started = false;
for(int32_t i = 99; i >= 0; i--) {
std::string cur = std::to_string(data[i]);
if(data[i] == 0 && !started)
continue;
if(started)
while(cur.size() < 3)
cur = "0" + cur;
started = true;
std::cout << cur;
}
}
bool operator<(BigInt other) {
for(int32_t i = 99; i >= 0; i--)
if(data[i] != other.data[i])
return data[i] < other.data[i];
return false;
}
};
BigInt int_sqrt(BigInt n) {
BigInt left, right = BigInt(std::string(100, '9'));
while(BigInt("1") < right - left) {
BigInt m = (left + right).half();
if(m * m < n)
left = m;
else
right = m;
}
return right;
}
int main() {
std::string n_str;
std::cin >> n_str;
BigInt n(n_str);
BigInt block = (int_sqrt(n * BigInt("8") + 1)).half();
BigInt block_end = (block * (block + 1)).half();
BigInt block_start = block_end - block + 1;
BigInt ans = block_start + ((block - 1) * (block - 2)).half() + (n - block_start) * BigInt("2");
ans.output();
return 0;
}
//0 0 1 3 6 10
//1, 2, 4, 5, 7, 9, 10, 12, 14, 16, 17 19 21 23 25 26
//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |