Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77c540a

Browse files
Lot of contest codes
1 parent e7a7f59 commit 77c540a

Some content is hidden

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

74 files changed

+7170
-1
lines changed

‎CSUBQ.cpp

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Deleted code is debugged code :)
3+
*/
4+
#include <bits/stdc++.h>
5+
#define ll long long
6+
#define ull unsigned long long
7+
#define vi vector<ll>
8+
#define pp pair<ll,ll>
9+
#define mp make_pair
10+
#define PI acos(-1.0)
11+
#define all(v) v.begin(),v.end()
12+
#define pb push_back
13+
#define FOR(i,a,b) for(i=a;i<b;i++)
14+
#define FREV(i,a,b) for(i=a;i>=b;i--)
15+
#define READ(a,i,n) FOR(i,0,n) { a[i] = read_ll();}
16+
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
17+
#define S(n) scanf("%lld", &n)
18+
#define INF 1e18
19+
#define MOD 1000000007
20+
21+
#ifndef ONLINE_JUDGE
22+
#define gc getchar
23+
#define pc putchar
24+
#else
25+
#define gc getchar_unlocked
26+
#define pc putchar_unlocked
27+
#endif
28+
29+
using namespace std;
30+
31+
int read_int() {
32+
char c = gc();
33+
while((c < '0' || c > '9') && c != '-') c = gc();
34+
int ret = 0, neg = 0;
35+
if (c == '-') neg = 1, c = gc();
36+
while(c >= '0' && c <= '9') {
37+
ret = 10 * ret + c - 48;
38+
c = gc();
39+
}
40+
return neg ? -ret : ret;
41+
}
42+
43+
ll read_ll() {
44+
char c = gc();
45+
while((c < '0' || c > '9') && c != '-') c = gc();
46+
ll ret = 0;
47+
int neg = 0;
48+
if (c == '-') neg = 1, c = gc();
49+
while(c >= '0' && c <= '9') {
50+
ret = 10 * ret + c - 48;
51+
c = gc();
52+
}
53+
return neg ? -ret : ret;
54+
}
55+
56+
/*******************************************RANDOM STUFF BEGINS HERE**************************************************/
57+
struct node {
58+
ll len;
59+
ll res, prefix, suffix;
60+
node(ll value = 0) {
61+
assert(value == 0 or value == 1);
62+
len = 1;
63+
res = prefix = suffix = value;
64+
}
65+
};
66+
67+
vector<node> segL, segR;
68+
ll L,R;
69+
70+
node merge(node a, node b) {
71+
node combined;
72+
73+
combined.len = a.len + b.len;
74+
75+
combined.res = a.res + b.res + a.suffix * b.prefix;
76+
77+
combined.prefix = a.prefix;
78+
if (a.prefix == a.len) {
79+
combined.prefix += b.prefix;
80+
}
81+
82+
combined.suffix = b.suffix;
83+
if (b.suffix == b.len) {
84+
combined.suffix += a.suffix;
85+
}
86+
87+
return combined;
88+
89+
}
90+
91+
92+
void updateUtil(ll t, ll index, ll value, ll l, ll r) {
93+
if (l == r) {
94+
segL[t] = node(value < L);
95+
segR[t] = node(value < R+1);
96+
return;
97+
}
98+
99+
ll m = (l + r) / 2;
100+
if (index <= m) {
101+
updateUtil(2*t+1, index, value, l, m);
102+
}
103+
else {
104+
updateUtil(2*t+2, index, value, m+1, r);
105+
}
106+
107+
segL[t] = merge(segL[2*t+1], segL[2*t+2]);
108+
segR[t] = merge(segR[2*t+1], segR[2*t+2]);
109+
}
110+
111+
void update(ll index, ll value, ll n) {
112+
updateUtil(0, index, value, 0, n-1);
113+
}
114+
115+
void build_tree(ll n) {
116+
ll i;
117+
FOR(i,0,n) {
118+
update(i,0,n);
119+
}
120+
}
121+
122+
node queryUtil(vector<node> &seg, ll t, ll l, ll r, ll start, ll end) {
123+
if (l > end or r < start or start > end) {
124+
return node();
125+
}
126+
127+
if (l <= start and end <= r) {
128+
return seg[t];
129+
}
130+
131+
ll m = (start + end) / 2;
132+
return merge(queryUtil(seg, 2*t+1, l, r, start, m), queryUtil(seg, 2*t+2, l, r, m+1, end));
133+
}
134+
135+
ll query(ll l, ll r, ll n) {
136+
return queryUtil(segR, 0, l, r, 0, n-1).res - queryUtil(segL, 0, l, r, 0, n-1).res;
137+
}
138+
139+
int main() {
140+
ll i,j,n,q,l,r,ch,x,y;
141+
n = read_ll();
142+
q = read_ll();
143+
L = read_ll();
144+
R = read_ll();
145+
146+
segL.resize(4*n);
147+
segR.resize(4*n);
148+
149+
build_tree(n);
150+
151+
FOR(i,0,q) {
152+
ch = read_ll();
153+
if (ch == 1) {
154+
x = read_ll();
155+
y = read_ll();
156+
update(x-1,y,n);
157+
}
158+
else {
159+
l = read_ll();
160+
r = read_ll();
161+
printf("%lld\n", query(l-1,r-1,n));
162+
}
163+
}
164+
return 0;
165+
}

‎Codeforces/101510/B.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Deleted code is debugged code :)
3+
*/
4+
#include <bits/stdc++.h>
5+
#define ll long long
6+
#define ull unsigned long long
7+
#define vi vector<ll>
8+
#define pp pair<ll,ll>
9+
#define mp make_pair
10+
#define PI acos(-1.0)
11+
#define all(v) v.begin(),v.end()
12+
#define pb push_back
13+
#define FOR(i,a,b) for(i=a;i<b;i++)
14+
#define FREV(i,a,b) for(i=a;i>=b;i--)
15+
#define READ(a,i,n) FOR(i,0,n) { a[i] = read_ll();}
16+
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
17+
#define S(n) scanf("%lld", &n)
18+
#define INF 1e18
19+
#define MOD 1000000007
20+
21+
// #ifndef ONLINE_JUDGE
22+
// #define gc getchar
23+
// #define pc putchar
24+
// #else
25+
// #define gc getchar_unlocked
26+
// #define pc putchar_unlocked
27+
// #endif
28+
29+
using namespace std;
30+
31+
// int read_int() {
32+
// char c = gc();
33+
// while((c < '0' || c > '9') && c != '-') c = gc();
34+
// int ret = 0, neg = 0;
35+
// if (c == '-') neg = 1, c = gc();
36+
// while(c >= '0' && c <= '9') {
37+
// ret = 10 * ret + c - 48;
38+
// c = gc();
39+
// }
40+
// return neg ? -ret : ret;
41+
// }
42+
43+
// ll read_ll() {
44+
// char c = gc();
45+
// while((c < '0' || c > '9') && c != '-') c = gc();
46+
// ll ret = 0;
47+
// int neg = 0;
48+
// if (c == '-') neg = 1, c = gc();
49+
// while(c >= '0' && c <= '9') {
50+
// ret = 10 * ret + c - 48;
51+
// c = gc();
52+
// }
53+
// return neg ? -ret : ret;
54+
// }
55+
56+
/*******************************************RANDOM STUFF BEGINS HERE**************************************************/
57+
58+
ll nCr(ll n, ll r) {
59+
ll i, ans = 1;
60+
r = min(r,n-r);
61+
FOR(i,0,r) {
62+
ans *= (n-i)/(i+1);
63+
}
64+
return ans;
65+
}
66+
67+
int main() {
68+
ll i,j,t,n,A,B,r1,s1,r2,s2;
69+
S(A);S(B);
70+
S(r1);S(s1);S(r2);S(r2);
71+
vi res(10,0);
72+
73+
// Straight flush
74+
if (s1 != s2 or abs(r1-r2) > 4) {
75+
res[1] = 0
76+
}
77+
else {
78+
ll done = abs(r1-r2) + 1;
79+
res[1] = 5 - done + 1;
80+
}
81+
82+
// Four of a kind
83+
if (r1 != r2) {
84+
res[2] = 2 * nCr(B-1,3);
85+
}
86+
else {
87+
res[2] = nCr(B-1,2) * ((A-1)*B);
88+
}
89+
90+
// Full House
91+
if (r1 != r2) {
92+
res[3] = nCr(B-1,2) * nCr(B-1,1) * 2;
93+
}
94+
else {
95+
res[3] = nCr(B-2,1) * nCr(B,2) * (A-1) + nCr(B,3) * (A-1);
96+
}
97+
98+
// Flush
99+
if (s1 != s2) {
100+
res[4] = 0;
101+
}
102+
else {
103+
res[4] = nCr(A-2,3) - res[1];
104+
}
105+
106+
// Straight
107+
if(abs(r1-r2) > 4 or r1 == r2) {
108+
res[5] = 0;
109+
}
110+
else {
111+
ll middle = pow(B,(abs(r1-r2) - 1));
112+
ll rem = 5 - abs(r1-r2) - 1;
113+
ll sides = (rem+1) * pow(B,rem);
114+
res[5] = middle * sides;
115+
}
116+
return 0;
117+
}

‎Codeforces/101510/C.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Deleted code is debugged code :)
3+
*/
4+
#include <bits/stdc++.h>
5+
#define ll long long
6+
#define ull unsigned long long
7+
#define vi vector<ll>
8+
#define pp pair<ll,ll>
9+
#define mp make_pair
10+
#define PI acos(-1.0)
11+
#define all(v) v.begin(),v.end()
12+
#define pb push_back
13+
#define FOR(i,a,b) for(i=a;i<b;i++)
14+
#define FREV(i,a,b) for(i=a;i>=b;i--)
15+
#define READ(a,i,n) FOR(i,0,n) { a[i] = read_ll();}
16+
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
17+
#define S(n) scanf("%lld", &n)
18+
#define INF 1e18
19+
#define MOD 1000000007
20+
21+
// #ifndef ONLINE_JUDGE
22+
// #define gc getchar
23+
// #define pc putchar
24+
// #else
25+
// #define gc getchar_unlocked
26+
// #define pc putchar_unlocked
27+
// #endif
28+
29+
using namespace std;
30+
31+
// int read_int() {
32+
// char c = gc();
33+
// while((c < '0' || c > '9') && c != '-') c = gc();
34+
// int ret = 0, neg = 0;
35+
// if (c == '-') neg = 1, c = gc();
36+
// while(c >= '0' && c <= '9') {
37+
// ret = 10 * ret + c - 48;
38+
// c = gc();
39+
// }
40+
// return neg ? -ret : ret;
41+
// }
42+
43+
// ll read_ll() {
44+
// char c = gc();
45+
// while((c < '0' || c > '9') && c != '-') c = gc();
46+
// ll ret = 0;
47+
// int neg = 0;
48+
// if (c == '-') neg = 1, c = gc();
49+
// while(c >= '0' && c <= '9') {
50+
// ret = 10 * ret + c - 48;
51+
// c = gc();
52+
// }
53+
// return neg ? -ret : ret;
54+
// }
55+
56+
/*******************************************RANDOM STUFF BEGINS HERE**************************************************/
57+
//function to build segment tree for RangeMin query
58+
void build_rangemin_tree(ll* t_min, ll n) {
59+
ll i;
60+
for(i=n-1; i>0; i--) {
61+
t_min[i] = min(t_min[i<<1], t_min[i<<1|1]);
62+
}
63+
/*for(i=1; i<2*n; i++)
64+
cout<<t_min[i]<<" ";
65+
cout<<endl;*/
66+
}
67+
68+
//returns the minimum element in the range [l,r)
69+
ll range_min(ll* t, ll n, ll l, ll r) {
70+
ll minim = INT_MAX;
71+
for(l+=n, r+=n; l<r; l>>=1, r>>=1) {
72+
if(l & 1)
73+
minim = min(minim, t[l++]);
74+
if(r & 1)
75+
minim = min(minim, t[--r]);
76+
}
77+
return minim;
78+
}
79+
80+
int main() {
81+
ll i,j,n,k;
82+
S(n); S(k);
83+
ll len = n-k+1;
84+
vi a(n);
85+
ll t[2*len+1];
86+
FOR(i,0,n) {
87+
S(a[i]);
88+
}
89+
sort(all(a));
90+
FOR(i,0,len) {
91+
t[len+i] = abs(a[i] - a[i+k-1]);
92+
}
93+
build_rangemin_tree(t,len);
94+
ll res = 0;
95+
FOR(i,0,n) {
96+
ll l = max(0LL,i-k+1);
97+
ll r = min(i+1,len);
98+
res = max(res,range_min(t,len,l,r));
99+
}
100+
printf("%lld", res);
101+
102+
return 0;
103+
}

‎Codeforces/101510/test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n = input()
2+
r = input()
3+
r = min(r,n-r)
4+
ans = 1
5+
for i in range(r):
6+
ans = ans * (n-i)/(i+1)
7+
print ans

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /