Instantly share code, notes, and snippets.

# juanplopes/A.cpp

Created November 7, 2019 17:36
Show Gist options
• Save juanplopes/46b42240e6cdc3733108e5fa7609ca1e to your computer and use it in GitHub Desktop.
Codeforces Round #595 (Div. 3)
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
 #include #include using namespace std; int T[200]; int main() { ios_base::sync_with_stdio(false); int test; cin >> test; int N; while(cin >> N) { bool odd = false, even = false; for(int i=0; i> T[i]; if (T[i]%2 == 0) even = true; else odd = true; } sort(T, T+N); int mindif = 10000; for(int i=1; i 1 ? 1 : (even+odd)) << endl; } }
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
 #include #include #include using namespace std; int P[201000]; int V[201000]; int main() { ios_base::sync_with_stdio(false); int test; cin >> test; int N; while(cin >> N) { for(int i=1; i<=N; i++) cin >> P[i]; memset(V, 0, sizeof V); for(int i=1; i<=N; i++) { if (V[i] > 0) continue; int count = 1; int x = P[i]; while(x != i) { count++; x = P[x]; } V[i] = count; x = P[i]; while(x != i) { V[x] = count; x = P[x]; } } for(int i=1; i<=N; i++) { if (i>1) cout << " "; cout << V[i]; } cout << endl; } }
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
 #include #include #include using namespace std; long long T[1000]; int main() { ios_base::sync_with_stdio(false); long long test; cin >> test; long long N; while(cin >> N) { int count = 0; while(N > 0) { T[count++] = N%3; N/=3; } long long carry = 0; long long lastChange = -1; for(int i=0; i=0; i--) { answer *= 3; answer += i
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
 #include #include #include #include #include #define MAX using namespace std; struct Seg { int index, a, b; Seg(int index, int a, int b) : index(index), a(a), b(b) {} inline bool operator<(const Seg& that) const{ if (b!=that.b) return b>that.b; return index A[200200]; vector B[200200]; set S; int X[200200]; int main() { ios_base::sync_with_stdio(false); int N, K; while(cin >> N >> K) { memset(A, 0, sizeof A); memset(B, 0, sizeof B); int minn = 100000000; int maxx = 0; for(int i=0; i> a >> b; minn = min(minn, a); maxx = max(maxx, b); A[a].push_back(Seg(i, a, b)); B[b].push_back(Seg(i, a, b)); } int answer = 0; for(int i=minn; i<=maxx; i++) { for(int j=0; j K) { X[answer++] = S.begin()->index; S.erase(S.begin()); } for(int j=0; j0) cout << " "; cout << X[i]+1; } cout << endl; } }
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
 #include #include #include using namespace std; long long A[200100], B[200100]; long long T1[200100], T2[200100], TX[200100]; int main() { ios_base::sync_with_stdio(false); long long N, C; while(cin >> N >> C) { for(int i=0; i> A[i]; for(int i=0; i> B[i]; T1[0] = 0; T2[0] = 20000000000ll; for(int i=1; i0) cout << " "; cout << min(T1[i], T2[i]); } cout << endl; } }