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 10c514c

Browse files
Add submissions for Lunchtime
1 parent 5635e71 commit 10c514c

File tree

3 files changed

+253
-0
lines changed

3 files changed

+253
-0
lines changed

‎LunchTime/May17/POSTTREE.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 SULL(n) scanf("%llu", &n)
16+
#define INF 1e18
17+
#define MOD 1000000007
18+
19+
#ifndef ONLINE_JUDGE
20+
#define gc getchar
21+
#define pc putchar
22+
#else
23+
#define gc getchar_unlocked
24+
#define pc putchar_unlocked
25+
#endif
26+
27+
using namespace std;
28+
29+
int read_int() {
30+
char c = gc();
31+
while((c < '0' || c > '9') && c != '-') c = gc();
32+
int ret = 0, neg = 0;
33+
if (c == '-') neg = 1, c = gc();
34+
while(c >= '0' && c <= '9') {
35+
ret = 10 * ret + c - 48;
36+
c = gc();
37+
}
38+
return neg ? -ret : ret;
39+
}
40+
41+
ll read_ll() {
42+
char c = gc();
43+
while((c < '0' || c > '9') && c != '-') c = gc();
44+
ll ret = 0;
45+
int neg = 0;
46+
if (c == '-') neg = 1, c = gc();
47+
while(c >= '0' && c <= '9') {
48+
ret = 10 * ret + c - 48;
49+
c = gc();
50+
}
51+
return neg ? -ret : ret;
52+
}
53+
54+
/*******************************************RANDOM STUFF BEGINS HERE**************************************************/
55+
struct node {
56+
vi adj;
57+
};
58+
59+
vector<node> tree;
60+
vi depth(100005), span_parent(100005), dp(100005), val(100005);
61+
62+
void dfs(ll u) {
63+
ll temp_u = u;
64+
while (val[u] < val[span_parent[temp_u]]) {
65+
temp_u = span_parent[temp_u];
66+
}
67+
span_parent[u] = span_parent[temp_u];
68+
dp[u] = (depth[u] - depth[span_parent[temp_u]]) * val[u] + dp[span_parent[temp_u]];
69+
ll i, len = tree[u].adj.size();
70+
FOR(i,0,len) {
71+
ll v = tree[u].adj[i];
72+
depth[v] = depth[u] + 1;
73+
dfs(v);
74+
}
75+
}
76+
77+
int main() {
78+
ll i,j,t,n;
79+
n = read_ll();
80+
tree.resize(n+1);
81+
FOR(i,2,n+1) {
82+
j = read_ll();
83+
tree[j].adj.pb(i);
84+
span_parent[i] = j;
85+
}
86+
FOR(i,1,n+1) {
87+
val[i] = read_ll();
88+
}
89+
val[0] = -INF;
90+
span_parent[1] = dp[0] = 0;
91+
depth[0] = -1;
92+
dfs(1);
93+
94+
FOR(i,1,n+1) {
95+
printf("%lld ", dp[i]);
96+
}
97+
return 0;
98+
}

‎LunchTime/May17/PREFINVS.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define ull unsigned long long
4+
#define vi vector<ll>
5+
#define pp pair<ll,ll>
6+
#define mp make_pair
7+
#define PI acos(-1.0)
8+
#define all(v) v.begin(),v.end()
9+
#define pb push_back
10+
#define FOR(i,a,b) for(i=a;i<b;i++)
11+
#define FREV(i,a,b) for(i=a;i>=b;i--)
12+
#define SULL(n) scanf("%llu", &n)
13+
#define INF 1e18
14+
#define MOD 1000000007
15+
16+
#ifndef ONLINE_JUDGE
17+
#define gc getchar
18+
#define pc putchar
19+
#else
20+
#define gc getchar_unlocked
21+
#define pc putchar_unlocked
22+
#endif
23+
24+
using namespace std;
25+
26+
int read_int() {
27+
char c = gc();
28+
while((c < '0' || c > '9') && c != '-') c = gc();
29+
int ret = 0, neg = 0;
30+
if (c == '-') neg = 1, c = gc();
31+
while(c >= '0' && c <= '9') {
32+
ret = 10 * ret + c - 48;
33+
c = gc();
34+
}
35+
return neg ? -ret : ret;
36+
}
37+
38+
ll read_ll() {
39+
char c = gc();
40+
while((c < '0' || c > '9') && c != '-') c = gc();
41+
ll ret = 0;
42+
int neg = 0;
43+
if (c == '-') neg = 1, c = gc();
44+
while(c >= '0' && c <= '9') {
45+
ret = 10 * ret + c - 48;
46+
c = gc();
47+
}
48+
return neg ? -ret : ret;
49+
}
50+
51+
int main() {
52+
ll i,j,t,n;
53+
string s;
54+
cin >> s;
55+
n = s.length();
56+
i = 0, j = 0;
57+
ll res = 0;
58+
bool flag = false;
59+
if(s[0] == '1') {
60+
while(s[i] == '1') {
61+
i++;
62+
}
63+
j = 1;
64+
}
65+
66+
while (i<n) {
67+
while (s[i] == '1') {
68+
flag = true;
69+
i++;
70+
}
71+
if(flag) {
72+
res++;
73+
}
74+
flag = false;
75+
i++;
76+
}
77+
78+
printf("%lld", 2*res+j);
79+
80+
return 0;
81+
}

‎LunchTime/May17/SUBINVER.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define ull unsigned long long
4+
#define vi vector<ll>
5+
#define pp pair<ll,ll>
6+
#define mp make_pair
7+
#define PI acos(-1.0)
8+
#define all(v) v.begin(),v.end()
9+
#define pb push_back
10+
#define FOR(i,a,b) for(i=a;i<b;i++)
11+
#define FREV(i,a,b) for(i=a;i>=b;i--)
12+
#define SULL(n) scanf("%llu", &n)
13+
#define INF 1e18
14+
#define MOD 1000000007
15+
16+
#ifndef ONLINE_JUDGE
17+
#define gc getchar
18+
#define pc putchar
19+
#else
20+
#define gc getchar_unlocked
21+
#define pc putchar_unlocked
22+
#endif
23+
24+
using namespace std;
25+
26+
int read_int() {
27+
char c = gc();
28+
while((c < '0' || c > '9') && c != '-') c = gc();
29+
int ret = 0, neg = 0;
30+
if (c == '-') neg = 1, c = gc();
31+
while(c >= '0' && c <= '9') {
32+
ret = 10 * ret + c - 48;
33+
c = gc();
34+
}
35+
return neg ? -ret : ret;
36+
}
37+
38+
ll read_ll() {
39+
char c = gc();
40+
while((c < '0' || c > '9') && c != '-') c = gc();
41+
ll ret = 0;
42+
int neg = 0;
43+
if (c == '-') neg = 1, c = gc();
44+
while(c >= '0' && c <= '9') {
45+
ret = 10 * ret + c - 48;
46+
c = gc();
47+
}
48+
return neg ? -ret : ret;
49+
}
50+
51+
int main() {
52+
ll i,j,t,n,q,l,r;
53+
n = read_ll();
54+
q = read_ll();
55+
string s,maxs;
56+
FOR(i,0,n) {
57+
s = s + '0';
58+
maxs = maxs + '0';
59+
}
60+
61+
FOR(i,0,q) {
62+
l = read_ll();
63+
r = read_ll();
64+
--l;
65+
--r;
66+
FOR(j,l,r+1) {
67+
s[j] = (s[j] == '1') ? '0' : '1';
68+
}
69+
if (s > maxs)
70+
maxs = s;
71+
}
72+
cout << maxs;
73+
return 0;
74+
}

0 commit comments

Comments
(0)

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