Skip to content

Commit affa8c3

Browse files
committed
...
1 parent 0bd9c4f commit affa8c3

File tree

627 files changed

+37987
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

627 files changed

+37987
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<bits/stdc++.h>
2+
#define ll long long int
3+
#define vl vector<ll>
4+
#define pll pair<ll,ll>
5+
#define vp vector<pll>
6+
#define pb(x) push_back(x)
7+
8+
using namespace std;
9+
10+
int main() {
11+
int n;
12+
ll x,y;
13+
vl pts;
14+
vp seg;
15+
scanf("%d", &n);
16+
for(int i=0; i<n; i++) {
17+
scanf("%lld %lld", &x,&y);
18+
pts.pb(r*x-y); pts.pb(r*x+y);
19+
seg.pb(pll(r*x-y, r*x+y));
20+
}
21+
sort(pts.begin(), pts.end());
22+
sort(seg.begin(), seg.end());
23+
24+
stack<int>
25+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <bits/stdc++.h>
2+
#define vii vector<ll>
3+
#define pb push_back
4+
#define pp pop_back
5+
#define LIM 500005
6+
#define pii pair<ll,ll>
7+
#define ff first
8+
#define ss second
9+
#define ll long long int
10+
#define EPS 1e-9
11+
12+
using namespace std;
13+
14+
bool cmp(pii a, pii b) {
15+
return (a.ff == b.ff && a.ss < b.ss) || a.ff > b.ff;
16+
}
17+
18+
/// for minimum
19+
struct CHT {
20+
int ptr, sz;
21+
vii M, B; /// y = Mx + C
22+
23+
CHT() {
24+
ptr = sz = 0;
25+
M.clear(); B.clear();
26+
}
27+
28+
bool bad(ll m, ll b) {
29+
return (b-B[sz-2])*(M[sz-2]-M[sz-1]) < (B[sz-1]-B[sz-2])*(M[sz-2]-m);
30+
}
31+
void addLine(int m, int b) {
32+
if(!M.empty() && M.back() == m) return;
33+
while(M.size() >= 2 && bad(m,b)) {
34+
M.erase(M.end()-1); B.erase(B.end()-1); sz--;
35+
}
36+
M.pb(m); B.pb(b);
37+
sz++;
38+
}
39+
40+
void printHull() {
41+
for(int i=0; i<sz; i++) cout << i << " : " << M[i] << ' ' << B[i] << endl;
42+
}
43+
44+
double getY(int pos, double x) {
45+
return M[pos]*x + B[pos];
46+
}
47+
ll sortedQuery(ll c, ll d) { /// pointer
48+
double x = 1.0*c/d;
49+
while(ptr < M.size()-1 && getY(ptr+1, x) <= getY(ptr, x) + EPS ) ptr++;
50+
ll ans = M[ptr]*c + B[ptr]*d;
51+
return ans;
52+
}
53+
int BSQuery(int x) { /// binary search
54+
55+
}
56+
};
57+
58+
bool cmpx(pair<pii,pii>a, pair<pii,pii> b) {
59+
return 1.0*a.ss.ff/a.ss.ss <= 1.0*b.ss.ff/b.ss.ss ;
60+
}
61+
bool cmpy(pair<pii,pii>a, pair<pii,pii>b) {
62+
return a.ff.ff < b.ff.ff;
63+
}
64+
65+
int n,m;
66+
pii lines[LIM];
67+
pair<pii,pii> q[LIM];
68+
69+
int main() {
70+
CHT cht;
71+
72+
scanf("%d", &n);
73+
for(int i=0; i<n; i++) {
74+
scanf("%lld %lld", &q[i].ss.ff, &q[i].ss.ss);
75+
q[i].ff.ff = i;
76+
}
77+
scanf("%d", &m);
78+
for(int i=0; i<m; i++) scanf("%lld %lld", &lines[i].ff, &lines[i].ss);
79+
sort(lines, lines+m, cmp);
80+
sort(q, q+n, cmpx);
81+
82+
for(int i=0; i<m; i++) cht.addLine(lines[i].ff, lines[i].ss);
83+
84+
for(int i=0; i<n; i++) q[i].ff.ss = cht.sortedQuery(q[i].ss.ff, q[i].ss.ss);
85+
sort(q, q+n, cmpy);
86+
87+
for(int i=0; i<n; i++) {
88+
if(i) printf(" ");
89+
printf("%lld", q[i].ff.ss );
90+
}
91+
printf("\n");
92+
93+
return 0;
94+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main() {
6+
int lo = 1, hi = 1000000, md;
7+
char ans[4];
8+
9+
while(lo < hi) {
10+
md = (lo+hi + 1) / 2;
11+
printf("%d\n", md);
12+
// printf("%d %d %d\n", lo, md, hi);
13+
fflush(stdout);
14+
15+
scanf("%s", ans);
16+
if(ans[0] == '<') hi = md-1;
17+
else lo = md;
18+
}
19+
20+
printf("! %d\n", lo);
21+
fflush(stdout);
22+
23+
return 0;
24+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
///HEADERS
2+
#include <bits/stdc++.h>
3+
///PREPROCESSORS
4+
#define ll long long int
5+
#define ull unsigned ll
6+
#define vii vector<int>
7+
#define vll vector<ll>
8+
#define pb push_back
9+
#define LIM 100000
10+
#define MOD 1000000007
11+
#define MAX 10000000
12+
#define pi acos(-1)
13+
#define segVar int lft = node << 1 , rgt = (node << 1) + 1 , md = (st+ed) >> 1;
14+
#define pii pair<int,int>
15+
#define mpr make_pair
16+
#define EPS 1e-9
17+
#define sqr(x) ((x)*(x))
18+
#define gamma 0.5772156649
19+
#define harm(x) log(x) + gamma + 1.0/(2*x) - 1.0/(12*sqr(x))
20+
#define joshephus(n,k) j(int n, int k) {ll res = 1; for(ll i=2; i<=n; i++) res = (res+k-1) % i + 1; return res;}
21+
22+
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
23+
24+
///IMPORTANT EQUATIONS
25+
///STARS AND BARS : (n+k-1)C(k-1)
26+
///STIRLING TWO : F(n,k) = F(n-1,k-1) + k*(n-1,k); F(n,1) = 1 , F(n,n) = 1;
27+
///STIRLING ONE : F(n,k) = F(n-1,k-1) + (n-1)*(n-1,k); F(n,1) = (n-1)! , F(n,n) = 1;
28+
///CATALAN NUMBER : Cat(n) = Comb(2n,n) - Comb(2n,n-1) = Comb(2n,n)/(n+1);
29+
30+
using namespace std;
31+
32+
int n,k, u,v;
33+
vii graph[LIM+100];
34+
int vis[LIM+100];
35+
int binTree[LIM+100][2];
36+
ll dp[203][203][4];
37+
38+
void dfs(int u) {
39+
vis[u] = 1;
40+
int sz = graph[u].size();
41+
int l = -1;
42+
for(int i=0; i<sz; i++) {
43+
int v = graph[u][i];
44+
if(vis[v]) continue;
45+
if(l == -1) binTree[u][0] = v;
46+
else binTree[l][1] = v;
47+
l = v;
48+
49+
dfs(v);
50+
}
51+
}
52+
53+
ll f(int u, int rem, int c) {
54+
if(!u) {
55+
if(rem || c == 1) return 0;
56+
return 1;
57+
}
58+
if(dp[u][rem][c] != -1) return dp[u][rem][c];
59+
60+
ll ans = 0;
61+
62+
if(c == 0) {
63+
///age khali
64+
for(int r=0; r<=rem; r++) ans = (ans + f(binTree[u][0], r, 0)*f(binTree[u][1], rem-r , 0) ) % MOD; ///nei nai
65+
for(int r=0; r< rem; r++) ans = (ans + f(binTree[u][0], r, 1)*f(binTree[u][1], rem-r-1, 0) ) % MOD; ///nisi
66+
}
67+
else if(c == 1) {
68+
///age single nwa
69+
for(int r=0; r<rem ; r++) ans = (ans + f(binTree[u][0], r, 2)*f(binTree[u][1], rem-r-1, 2) ) % MOD; ///nisi
70+
for(int r=0; r<=rem; r++) ans = (ans + f(binTree[u][0], r, 0)*f(binTree[u][1], rem-r , 1) ) % MOD; ///nei nai
71+
}
72+
else {
73+
///age jora nwa
74+
for(int r=0; r<rem ; r++) ans = (ans + f(binTree[u][0], r, 2)*f(binTree[u][1], rem-r-1, 2) ) % MOD; ///nisi
75+
for(int r=0; r<=rem; r++) ans = (ans + f(binTree[u][0], r, 0)*f(binTree[u][1], rem-r , 2) ) % MOD; ///nei nai
76+
}
77+
return dp[u][rem][c] = ans;
78+
}
79+
80+
int main() {
81+
82+
// freopen("i.txt", "r", stdin);
83+
// freopen("o.txt", "w",stdout);
84+
85+
// memset(dp, -1, sizeof dp);
86+
87+
while(scanf("%d %d", &n,&k) != EOF) {
88+
memset(graph, NULL, sizeof graph);
89+
memset(binTree, 0, sizeof binTree);
90+
memset(vis, 0, sizeof vis);
91+
memset(dp, -1, sizeof dp);
92+
for(int i=1; i<n; i++) {
93+
scanf("%d %d", &u,&v);
94+
graph[u].pb(v);
95+
graph[v].pb(u);
96+
}
97+
dfs(1);
98+
printf("%lld\n", f(1, k, 0) );
99+
}
100+
101+
102+
return 0;
103+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#include<bits/stdc++.h>
2+
#define vl vector<ll>
3+
#define pb push_back
4+
5+
using namespace std;
6+
7+
typedef long double ld;
8+
ld PI = acosl(-1);
9+
typedef long long ll;
10+
typedef pair<int, int> ii;
11+
12+
struct cplx {
13+
ld a, b;
14+
cplx(ld a = 0, ld b = 0) : a(a), b(b) {}
15+
const cplx operator + (const cplx &c) const
16+
{ return cplx(a + c.a, b + c.b); }
17+
const cplx operator - (const cplx &c) const
18+
{ return cplx(a - c.a, b - c.b); }
19+
const cplx operator * (const cplx &c) const
20+
{ return cplx(a * c.a - b * c.b, a * c.b + b * c.a); }
21+
};
22+
typedef vector<cplx> vc;
23+
void fft(vc &p, bool inv = 0) {
24+
int n = p.size(), i = 0;
25+
for(int j = 1; j < n - 1; ++j) {
26+
for(int k = n >> 1; k > (i ^= k); k >>= 1);
27+
if(j < i) swap(p[i], p[j]);
28+
}
29+
for(int m = 2; m <= n; m <<= 1) {
30+
int mh = m >> 1;
31+
cplx wn = cplx(cos(2 * PI / m), sin(2 * PI / m));
32+
if(inv) wn = cplx(cos(2 * PI / m), -sin(2 * PI / m));
33+
for(int j = 0; j < n; j += m) {
34+
cplx w(1, 0);
35+
for(int k = 0; k < mh; ++k) {
36+
int pos = j + k;
37+
cplx t = w * p[pos + mh];
38+
p[pos + mh] = p[pos] - t;
39+
p[pos] = p[pos] + t;
40+
w = w * wn;
41+
}
42+
}
43+
} if(inv) for(int i = 0; i < n; i++) p[i].a /= n, p[i].b /= n;
44+
}
45+
vector<ll> multiply(vector<ll> &a, vector<ll> &b) {
46+
int n = a.size(), m = b.size(), t = n + m - 1, sz = 1;
47+
while(sz < t) sz <<= 1;
48+
vc x(sz), y(sz), z(sz);
49+
for(int i = 0 ; i < sz; ++i) {
50+
x[i] = i < a.size() ? cplx(a[i], 0) : cplx(0, 0);
51+
y[i] = i < b.size() ? cplx(b[i], 0) : cplx(0, 0);
52+
} fft(x), fft(y);
53+
for(int i = 0; i < sz; ++i) z[i] = x[i] * y[i];
54+
fft(z, 1);
55+
vector<ll> ret(t + 1);
56+
for(int i = 0; i <= t; ++i) ret[i] = z[i].a + 0.5;
57+
return ret;
58+
}
59+
60+
61+
62+
int main() {
63+
// freopen("in.txt", "r", stdin);
64+
65+
int n,m, i;
66+
67+
68+
while(scanf("%d %d", &n,&m) == 2) {
69+
70+
string str, pat;
71+
vl ans, a,b, temp;
72+
cin >> str;
73+
cin >> pat;
74+
reverse(pat.begin(), pat.end());
75+
76+
for(int i=0; i<n; i++) ans.pb(0);
77+
for(int i=0; i<n; i++) a.pb(0);
78+
for(int i=0; i<m; i++) b.pb(0);
79+
80+
///rock
81+
for(int i=0; i<n; i++) {
82+
if(str[i] == 'S') a[i] = 1;
83+
else a[i] = 0;
84+
}
85+
for(int i=0; i<m; i++) {
86+
if(pat[i] == 'R') b[i] = 1;
87+
else b[i] = 0;
88+
}
89+
temp = multiply(a,b);
90+
// for(int i=m-1; i<n; i++) cout << temp[i]; cout << endl;
91+
// for(i=m-1; i<temp.size() && i<ans.size(); i++) ans[i] = temp[i];
92+
// for(i=m-1; i<n i++) ans[i] = temp[i];
93+
ans = temp;
94+
95+
///paper
96+
for(int i=0; i<n; i++) {
97+
if(str[i] == 'R') a[i] = 1;
98+
else a[i] = 0;
99+
}
100+
for(int i=0; i<m; i++) {
101+
if(pat[i] == 'P') b[i] = 1;
102+
else b[i] = 0;
103+
}
104+
temp = multiply(a,b);
105+
// for(int i=m-1; i<n; i++) cout << temp[i]; cout << endl;
106+
// for(i=m-1; i<temp.size() && i<ans.size(); i++) ans[i] += temp[i];
107+
for(i=0; i<temp.size(); i++) ans[i] += temp[i];
108+
// while(i<temp.size()) ans.pb(temp[i++]);
109+
110+
///scissor
111+
for(int i=0; i<n; i++) {
112+
if(str[i] == 'P') a[i] = 1;
113+
else a[i] = 0;
114+
}
115+
for(int i=0; i<m; i++) {
116+
if(pat[i] == 'S') b[i] = 1;
117+
else b[i] = 0;
118+
}
119+
temp = multiply(a,b);
120+
// for(int i=m-1; i<n; i++) cout << temp[i]; cout << endl;
121+
// for(int i=m-1; i<temp.size() && i<ans.size(); i++) ans[i] += temp[i];
122+
for(int i=0; i<temp.size(); i++) ans[i] += temp[i];
123+
// while(i<temp.size()) ans.pb(temp[i++]);
124+
125+
ll answer = 0;
126+
for(int i=m-1; i<temp.size(); i++) if(temp[i] <= m) answer = max(answer, ans[i]);
127+
128+
printf("%lld\n", answer);
129+
130+
}
131+
132+
return 0;
133+
// main();
134+
}

0 commit comments

Comments
 (0)