You are on page 1of 9

Morgan is making N atomic soups numbered 1 through N.

Each soup is either a base atomic soup or a


composition of other atomic soups. For each valid i, if soup i is not a base soup, one unit of this soup
is made by mixing together one unit of soup ci,1, one unit of soup ci,2, and so on to one unit of
soup ci,pi. Note that these Pi soup units are not necessarily from distinct soups and that we obtain only
1 unit of soup by mixing Pi units.

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long

typedef pair<int, int> ii;

const int mod = 1e9 + 7;


const int inf = 1e9;

int add(int x, int y) {


return (1ll * x + 1ll * y) % mod;
}

int mul(int x, int y) {


return (1ll * x * 1ll * y) % mod;
}

int del(int x, int y) {


return ((1ll * x - 1ll * y) % mod + mod) % mod;
}

const int N = 2e4 + 5;


const int X = 63;

int val[N];

int no_of_soups, queries;

int gen() {
int lmao = 0;
for(int i = 0; i < X; i++) {
int y = rand() % 5;
if(!y) lmao |= (1ll << i);
}
return lmao;
}

bool gauss(vector<int> vec) {


for(int i = 0; i < vec.size(); i++) {
if(!vec[i]) return 1;
}
int cur = 0;
for(int i = 0; i < X; i++) {
for(int j = cur; j < vec.size(); j++) {
if((vec[j] & (1ll << i))) {
swap(vec[cur], vec[j]);
for(int k = 0; k < vec.size(); k++) {
if(k != cur && (vec[k] & (1ll << i))) {
vec[k] ^= vec[cur];
}
}
cur++;
break;
}
}
}
for(int j = 0; j < vec.size(); j++) {
if(!vec[j])
return 1;
}
return 0;
}

signed main() {
cin.tie(0), ios::sync_with_stdio(0);
srand(time(0));
cin >> no_of_soups;
for(int i = 1; i <= no_of_soups; i++)
val[i] = gen();
for(int i = 1; i <=no_of_soups; i++) {
int sz, y;
cin >> sz;
if(sz) {
int lmao = 0;
while(sz--) {
cin >> y;
lmao ^= val[y];
}
val[i] = lmao;
}
}
cin >> queries;
while(queries--) {
vector<int> vec;
int sz, y;
cin >> sz;
while(sz--) {
cin >> y;
vec.pb(val[y]);
}
cout << gauss(vec);
}
}

Aaron has a friend named Hardik who is very good at geometry. One day Aaron came across an
interesting problem on the topic of circles and shared it with Hardik. Next day Hardik also came up to
Aaron with a problem he just created. When our Aaron couldn't solve it thinking that it uses some
advanced geometry, Hardik took the pleasure saying that the solution of this problem uses exactly the
same concept which was used to solve the problem that they have discussed the day before. This came
as a shock to our Aaron and he became desperate to solve this problem, but even as he tried a lot, he
couldn't solve it. Hardik doesn't want to share his solution, so can you help our Aaron in solving the
problem?
Take a deep breath! You are going to draw a lot of circles.

#include <bits/stdc++.h>

#define getcx getchar

using namespace std;

struct Matrix {
int a, b, c;
int d, e, f;
int p, q, r;
};

Matrix unit = {1, 0, 0, 0, 1, 0, 0, 0, 1};


Matrix R = {2, -1, 1, 1, 0, 0, 0, 0, 1};

Matrix multiply(Matrix m1, Matrix m2) {


Matrix m3;
m3.a = m1.a * m2.a + m1.b * m2.d + m1.c * m2.p;
m3.b = m1.a * m2.b + m1.b * m2.e + m1.c * m2.q;
m3.c = m1.a * m2.c + m1.b * m2.f + m1.c * m2.r;

m3.d = m1.d * m2.a + m1.e * m2.d + m1.f * m2.p;


m3.e = m1.d * m2.b + m1.e * m2.e + m1.f * m2.q;
m3.f = m1.d * m2.c + m1.e * m2.f + m1.f * m2.r;

m3.p = m1.p * m2.a + m1.q * m2.d + m1.r * m2.p;


m3.q = m1.p * m2.b + m1.q * m2.e + m1.r * m2.q;
m3.r = m1.p * m2.c + m1.q * m2.f + m1.r * m2.r;

return m3;
}

void print(Matrix m) {
cout << endl;

cout << m.a << " " << m.b << " " << m.c << endl;
cout << m.d << " " << m.e << " " << m.f << endl;
cout << m.p << " " << m.q << " " << m.r << endl;

cout << endl;


}

inline Matrix poww(Matrix b, int e) {


Matrix p = unit;

while (e > 0) {
if(e % 2 != 0) {
p = multiply(p, b);
}
e = e / 2;
b = multiply(b, b);
}

return p;
}

inline Matrix power(Matrix m1, int n) {


if (n <= 0) {
return unit;
} else if (n == 1) {
return m1;
} else if (n == 2) {
return multiply(m1, m1);
} else if (n == 3) {
return multiply(multiply(m1, m1), m1);
}

Matrix m2 = power(m1, n / 2);

if (n & 1) {
return multiply(multiply(m2, m2), m1);
} else {
return multiply(m2, m2);
}
}

int main() {
int t;
long long n;
int P, M, B;

cin >> n >> P >> M >> B;

double r[5000], ans = 0;


cin >> r[1] >> r[2] >> r[3] >> r[4];

n = (P * n) % M + B;
if (n <= 4) {
ans += r[n];
}

double a = 1 / r[4];
double b = 1 / r[3];
double c = 2 * (-1 / r[1] + 1 / r[2]);

double tmpp = (0.5) * (n - 4) * (c * (n - 3) - 2 * b) + (n - 3) * a; //m.a * a + m.b * b +


m.c * c;

ans += 1 / tmpp;
cout<<ans;
}

The world economy depends on oil, so only new methods for finding and extracting oil is still active.
Profits of oil companies depend in part on how efficiently they can drill for oil. The Petroleum
Consortium (PC) hopes that extensive computer simulations will make it easier to determine how to
drill oil wells in the best possible way.
Drilling oil wells is getting harder each day. The newly discovered oil deposits often do not form a
single body but are split into many parts. The PC is currently concerned with stratified deposits, as
illustrated in Figure 1.

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

bool slopecmp(const pair<int, pair<int, int> >& a,


const pair<int, pair<int, int> >& b) {
long long av = (long long)a.second.first * b.second.second;
long long bv = (long long)b.second.first * a.second.second;
if (av != bv) return av < bv;
return a.first > b.first;
}

main() {
int N;
while (cin >> N) {
vector<int> x1(N), x2(N), y(N);
for (int i = 0; i < N; i++) {
cin >> x1[i] >> x2[i] >> y[i];
if (x1[i] > x2[i]) swap(x1[i], x2[i]);
}
int ret = 0;
for (int i = 0; i < N; i++) {
vector<pair<int, pair<int, int> > > v;
int cur = 0;
for (int j = 0; j < N; j++) {
if (y[j] == y[i]) {
if (x1[i] >= x1[j] && x1[i] <= x2[j]) {
cur += x2[j]-x1[j];
}
} else if (y[j] < y[i]) {
v.push_back(make_pair(x2[j]-x1[j], make_pair(x1[i]-x2[j], y[i]-y[j])));
v.push_back(make_pair(x1[j]-x2[j], make_pair(x1[i]-x1[j], y[i]-y[j])));
} else {
v.push_back(make_pair(x2[j]-x1[j], make_pair(x1[j]-x1[i], y[j]-y[i])));
v.push_back(make_pair(x1[j]-x2[j], make_pair(x2[j]-x1[i], y[j]-y[i])));
}
}
sort(v.begin(), v.end(), slopecmp);
ret = max(ret, cur);
for (int j = 0; j < v.size(); j++) {
cur += v[j].first;
ret = max(ret, cur);
}
}
cout << ret << endl;
}
}

You might also like