Created
October 6, 2017 20:08
-
-
Save vstrimaitis/cd85a3fd99a5c13785de8743abfe03f7 to your computer and use it in GitHub Desktop.
OC solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <iostream> | |
#include <iomanip> | |
#include <fstream> | |
#include <stdio.h> | |
#include <cstdio> | |
#include <stdlib.h> | |
#include <cstdlib> | |
#include <algorithm> | |
#include <cstring> | |
#include <string> | |
#include <vector> | |
#include <list> | |
#include <stack> | |
#include <climits> | |
#include <set> | |
#include <bitset> | |
#include <math.h> | |
#include <queue> | |
#include <map> | |
#include <sstream> | |
#include <functional> | |
#include <assert.h> | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <complex> | |
typedef long long ll; | |
typedef unsigned long long ull; | |
typedef long double ld; | |
typedef std::pair<int, int> pii; | |
typedef std::pair<double, double> pdd; | |
template <typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; | |
template <typename T> using max_heap = std::priority_queue<T, std::vector<T>, std::less<T>>; | |
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); | |
#define TESTS(t) int NUMBER_OF_TESTS; cin >> NUMBER_OF_TESTS; for(int t = 1; t <= NUMBER_OF_TESTS; t++) | |
#define FOR(i, start, end) for(int i = (start); i < (end); i++) | |
#define ROF(i, start, end) for(int i = (start); i >= (end); i--) | |
#define all(x) (x).begin(), (x).end() | |
//#define endl "\n" | |
#define PI (asin(1)*2) | |
#define OO ((1LL<<31)-1) | |
#define eps 1e-12 | |
#define in(a, b) ((b).find(a) != (b).end()) | |
#define mp(a, b) make_pair((a), (b)) | |
#define sgn(a) ((a) > eps ? 1 : ((a) < -eps ? -1 : 0)) | |
#define cl1(x) ((x)&((x)-1)) // clear lowest 1 bit | |
#define cl0(x) ((x)|((x)+1)) // clear lowest 0 bit | |
#define ct1(x) ((x)&((x)+1)) // clear all trailing 1 bits | |
#define pb push_back | |
#define MOD 1000000007 | |
#define MAX_N 100000 | |
using namespace std; | |
map<char, int> bin; | |
map<int, char> lol; | |
map<int, int> skip; | |
vector<vector<string>> subsets; | |
void init() { | |
bin['0'] = 0; | |
bin['1'] = 1; | |
bin['2'] = 2; | |
bin['3'] = 3; | |
bin['4'] = 4; | |
bin['5'] = 5; | |
bin['6'] = 6; | |
bin['7'] = 7; | |
bin['8'] = 8; | |
bin['9'] = 9; | |
bin['A'] = 10; | |
bin['B'] = 11; | |
bin['C'] = 12; | |
bin['D'] = 13; | |
bin['E'] = 14; | |
bin['F'] = 15; | |
lol[1] = '1'; | |
lol[2] = '2'; | |
lol[3] = '3'; | |
lol[4] = '4'; | |
lol[5] = '5'; | |
lol[6] = '6'; | |
lol[7] = '7'; | |
lol[8] = '8'; | |
lol[9] = '9'; | |
lol[10] = 'A'; | |
lol[11] = 'B'; | |
lol[12] = 'C'; | |
lol[13] = 'D'; | |
lol[14] = 'E'; | |
lol[15] = 'F'; | |
lol[0] = '0'; | |
skip[0] = 1; | |
FOR(i, 1, 6) skip[i] = i + 2; | |
vector<string> v; | |
subsets.pb(v); | |
} | |
string toBin(int val) { | |
string res = ""; | |
while (val > 0) { | |
res += (val % 2) + '0'; | |
val /= 2; | |
} | |
reverse(res.begin(), res.end()); | |
while (res.length() != 4) { | |
res = "0" + res; | |
} | |
return res; | |
} | |
int isGoodFirstByte(string byte) { | |
char c = byte[0]; | |
int val = bin[c]; | |
val <<= 4; | |
val += bin[byte[1]]; | |
if ((val & 128) == 0) return 0; | |
if (((val&(7 << 5)) >> 5) == 6) return 1; | |
if (((val&(15 << 4)) >> 4) == 14) return 2; | |
if (((val&(31 << 3)) >> 3) == 30) return 3; | |
if (((val&(63 << 2)) >> 2) == 62) return 4; | |
if (((val&(127 << 1)) >> 1) == 126) return 5; | |
return -1; | |
} | |
bool isGoodFollowingByte(string c) { | |
int val = bin[c[0]]; | |
val <<= 4; | |
return (((val&(3 << 6)) >> 6) == 2); | |
} | |
string getTrailing(string hex, int skip) { | |
string bbin = toBin(bin[hex[0]]) + toBin(bin[hex[1]]); | |
return bbin.substr(skip); | |
} | |
string toHex(string bin) { | |
string hex = ""; | |
for (int i = bin.length() - 1; i >= 0; i-=4) { | |
int val = 0; | |
int d = 1; | |
for (int j = 0; j < 4 && i-j >= 0; j++, d <<= 1) { | |
val += (bin[i - j] - '0')*d; | |
} | |
hex += lol[val]; | |
} | |
reverse(hex.begin(), hex.end()); | |
int toSkip = 0; | |
for (char c : hex) { | |
if (c == '0') toSkip++; | |
else break; | |
} | |
string res = hex.substr(toSkip); | |
return res.length() == 0 ? "0" : res; | |
} | |
string carry = ""; | |
void readValue(string firstByte, int type) { | |
string val = ""; | |
val += getTrailing(firstByte, skip[type]); | |
for (int i = 0; i < type; i++) { | |
string byte; cin >> byte; | |
if (!isGoodFollowingByte(byte)) { | |
vector<string> v; | |
subsets.pb(v); | |
carry = byte; | |
return; | |
} | |
val += getTrailing(byte, 2); | |
} | |
subsets[subsets.size() - 1].pb(toHex(val)); | |
} | |
string byte; | |
bool getNext() { | |
if (carry == "") { | |
return (bool)(cin >> byte); | |
} | |
else { | |
byte = carry; | |
return true; | |
} | |
} | |
int main() | |
{ | |
FAST_IO | |
#ifdef _DEBUG | |
freopen("input.txt", "r", stdin); | |
freopen("output.txt", "w", stdout); | |
#endif | |
init(); | |
while (getNext()) { | |
carry = ""; | |
int type = isGoodFirstByte(byte); | |
if (type != -1) { | |
readValue(byte, type); | |
} | |
else { | |
vector<string> v; | |
subsets.pb(v); | |
} | |
} | |
for (auto s : subsets) { | |
if (s.size() < 3) continue; | |
for (auto val : s) { | |
cout << val << " "; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <iostream> | |
#include <iomanip> | |
#include <fstream> | |
#include <stdio.h> | |
#include <cstdio> | |
#include <stdlib.h> | |
#include <cstdlib> | |
#include <algorithm> | |
#include <cstring> | |
#include <string> | |
#include <vector> | |
#include <list> | |
#include <stack> | |
#include <climits> | |
#include <set> | |
#include <bitset> | |
#include <math.h> | |
#include <queue> | |
#include <map> | |
#include <sstream> | |
#include <functional> | |
#include <assert.h> | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <complex> | |
typedef long long ll; | |
typedef unsigned long long ull; | |
typedef long double ld; | |
typedef std::pair<int, int> pii; | |
typedef std::pair<double, double> pdd; | |
template <typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; | |
template <typename T> using max_heap = std::priority_queue<T, std::vector<T>, std::less<T>>; | |
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); | |
#define TESTS(t) int NUMBER_OF_TESTS; cin >> NUMBER_OF_TESTS; for(int t = 1; t <= NUMBER_OF_TESTS; t++) | |
#define FOR(i, start, end) for(int i = (start); i < (end); i++) | |
#define ROF(i, start, end) for(int i = (start); i >= (end); i--) | |
#define all(x) (x).begin(), (x).end() | |
//#define endl "\n" | |
#define PI (asin(1)*2) | |
#define OO ((1LL<<31)-1) | |
#define eps 1e-12 | |
#define in(a, b) ((b).find(a) != (b).end()) | |
#define mp(a, b) make_pair((a), (b)) | |
#define sgn(a) ((a) > eps ? 1 : ((a) < -eps ? -1 : 0)) | |
#define cl1(x) ((x)&((x)-1)) // clear lowest 1 bit | |
#define cl0(x) ((x)|((x)+1)) // clear lowest 0 bit | |
#define ct1(x) ((x)&((x)+1)) // clear all trailing 1 bits | |
#define pb push_back | |
#define MOD 1000000007 | |
#define MAX_N 100000 | |
using namespace std; | |
vector<pair<int, int>> pts; | |
int total; | |
const int MAX = 1000000; | |
int foundInRange(int x1, int y1, int x2, int y2) { | |
int cnt = 0; | |
for (auto pt : pts) { | |
if (pt.first >= x1 && pt.first <= x2 && pt.second >= y1 && pt.second <= y2) | |
cnt++; | |
} | |
return cnt; | |
} | |
int query(int x, int y) { | |
cout << "? " << x << " " << y << endl; | |
int n; | |
cin >> n; | |
return n; | |
} | |
void solve(int x1, int y1, int x2, int y2, int exp) { | |
if (pts.size() == total) return; | |
if (exp == 0) return; | |
if (foundInRange(x1, y1, x2, y2) == exp) return; | |
if (x1 == x2 && y1 == y2) { | |
pts.pb({ x1, y1 }); | |
return; | |
} | |
if (x1 == x2) { | |
if (y2 == y1 + 1) { | |
int res = query(x1, y1); | |
res -= foundInRange(-MAX, -MAX, x1, y1); | |
solve(x1, y1, x1, y1, res); | |
solve(x2, y2, x2, y2, exp - res); | |
return; | |
} | |
int res = query( x2, (y1 + y2) / 2); | |
res -= foundInRange(-MAX, -MAX, x2, (y1 + y2) / 2); | |
if (res == exp) { | |
solve(x1, y1, x2, (y1 + y2) / 2, exp); | |
} | |
else { | |
solve(x1, y1, x2, (y1 + y2) / 2, res); | |
solve(x1, (y1 + y2) / 2 + 1, x2, y2, exp-res); | |
} | |
return; | |
} | |
/*if (y1 == y2) { | |
return; | |
}*/ | |
if (x2 == x1 + 1) { | |
int res = query(x1, y2); | |
res -= foundInRange(-MAX, -MAX, x1 - 1, y2); | |
solve(x1, y1, x1, y2, res); | |
solve(x2, y1, x2, y2, exp - res); | |
return; | |
} | |
int res = query((x2 + x1) / 2, y2); | |
res -= foundInRange(-MAX, -MAX, x1-1, y2); | |
res -= foundInRange(-MAX, -MAX, x2, y1 - 1); | |
res += foundInRange(-MAX, -MAX, x1 - 1, y1 - 1); | |
if (res == exp) { // everything on the left | |
solve(x1, y1, (x2 + x1) / 2, y2, exp); | |
} | |
else { | |
solve(x1, y1, (x2 + x1) / 2, y2, res); | |
solve((x2 + x1) / 2+1, y1, x2, y2, exp - res); | |
} | |
} | |
int main() | |
{ | |
FAST_IO | |
/*#ifdef _DEBUG | |
freopen("input.txt", "r", stdin); | |
freopen("output.txt", "w", stdout); | |
#endif*/ | |
cin >> total; | |
solve(-1000000, -1000000, 1000000, 1000000, total); | |
cout << "! "; | |
for (auto pt : pts) { | |
cout << pt.first << " " << pt.second << " "; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <iostream> | |
#include <iomanip> | |
#include <fstream> | |
#include <stdio.h> | |
#include <cstdio> | |
#include <stdlib.h> | |
#include <cstdlib> | |
#include <algorithm> | |
#include <cstring> | |
#include <string> | |
#include <vector> | |
#include <list> | |
#include <stack> | |
#include <climits> | |
#include <set> | |
#include <bitset> | |
#include <math.h> | |
#include <queue> | |
#include <map> | |
#include <sstream> | |
#include <functional> | |
#include <assert.h> | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <complex> | |
typedef long long ll; | |
typedef unsigned long long ull; | |
typedef long double ld; | |
typedef std::pair<int, int> pii; | |
typedef std::pair<double, double> pdd; | |
template <typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; | |
template <typename T> using max_heap = std::priority_queue<T, std::vector<T>, std::less<T>>; | |
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); | |
#define TESTS(t) int NUMBER_OF_TESTS; cin >> NUMBER_OF_TESTS; for(int t = 1; t <= NUMBER_OF_TESTS; t++) | |
#define FOR(i, start, end) for(int i = (start); i < (end); i++) | |
#define ROF(i, start, end) for(int i = (start); i >= (end); i--) | |
#define all(x) (x).begin(), (x).end() | |
#define endl "\n" | |
#define PI (asin(1)*2) | |
#define OO ((1LL<<31)-1) | |
#define eps 1e-12 | |
#define in(a, b) ((b).find(a) != (b).end()) | |
#define mp(a, b) make_pair((a), (b)) | |
#define sgn(a) ((a) > eps ? 1 : ((a) < -eps ? -1 : 0)) | |
#define cl1(x) ((x)&((x)-1)) // clear lowest 1 bit | |
#define cl0(x) ((x)|((x)+1)) // clear lowest 0 bit | |
#define ct1(x) ((x)&((x)+1)) // clear all trailing 1 bits | |
#define pb push_back | |
#define MOD 1000000007 | |
#define MAX_N 500 | |
using namespace std; | |
int main() | |
{ | |
FAST_IO | |
#ifdef _DEBUG | |
freopen("input.txt", "r", stdin); | |
freopen("output.txt", "w", stdout); | |
#endif | |
ull L, R, Q; | |
while (cin >> L >> R >> Q) { | |
if (Q > R) { | |
cout << "infinity" << endl; | |
continue; | |
} | |
if (L <= Q && Q <= R) { | |
ull ans = 0; | |
for (ull i = 1; i * i <= Q; i++) { | |
if (Q%i == 0) { | |
ans += 2; | |
if (i == Q / i) ans--; | |
} | |
} | |
cout << ans << endl; | |
continue; | |
} | |
if (Q < L) { | |
ull k = L / Q; | |
if (k*Q < L) k++; | |
if (k*Q > R) { | |
set<ull> div; | |
ull l = L%Q; | |
ull Ll = L - l; | |
for (ull x = 1; x * x <= Ll; x++) { | |
if (Ll % x == 0) { | |
ull a = x; | |
ull b = Ll / x; | |
if (a >= Q && L / a == R / a && L/a==Ll/a) { | |
div.insert(a); | |
} | |
if (b >= Q && L / b == R / b && R/b==Ll/b) { | |
div.insert(b); | |
} | |
if ((R - L)*L / 100 > 1000000000) { | |
if (Ll / a == L / a - (l + L - L) / a && | |
L / a - (l + L - L) / a == R / a - (l + R - L) / a) | |
div.insert(a); | |
if (Ll / b == L / b - (l + L - L) / b && | |
L / b - (l + L - L) / b == R / b - (l + R - L) / b) | |
div.insert(b); | |
} | |
else { | |
bool ok = true; | |
FOR(i, L, R + 1) { | |
if (Ll / a != i / a - (l - L + i) / a) ok = false; | |
} | |
if (ok) div.insert(a); | |
ok = true; | |
FOR(i, L, R + 1) { | |
if (Ll / b != i / b - (l - L + i) / b) ok = false; | |
} | |
if (ok) div.insert(b); | |
} | |
} | |
} | |
cout << div.size() << endl; | |
} | |
else if ((k + 1)*Q > R) { | |
/*if (k > 10 && Q > 1000) return 1; | |
unordered_map<ll, ll> cnt; | |
for (ll i = 2; i <= Q; i++) { | |
while (Q%i == 0 && Q > 0) { | |
cnt[i]++; | |
Q /= i; | |
} | |
}for (ll i = 2; i <= k; i++) { | |
while (k%i == 0 && k > 0) { | |
cnt[i]++; | |
k /= i; | |
} | |
} | |
ll ans = 1; | |
for (auto e : cnt) { | |
ans *= e.second+1; | |
} | |
cout << ans << endl; | |
cout << ans << endl;*/ | |
ll ans = 0; | |
set<ll> div; | |
ll l = L - L%Q; | |
for (ll i = 1; i * i <= k*Q; i++) { | |
if ((k*Q)%i == 0) { | |
ll a = i; | |
ll b = (k*Q) / i; | |
if (l%a == 0) div.insert(a); | |
if (l%b == 0) div.insert(b); | |
} | |
} | |
cout << div.size() << endl; | |
continue; | |
} | |
else { | |
ll ans = 0; | |
for (ll i = 1; i * i <= Q; i++) { | |
if (Q%i == 0) { | |
ans += 2; | |
if (i == Q / i) ans--; | |
} | |
} | |
cout << ans << endl; | |
continue; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment