problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02418
C++
Runtime Error
#include <cctype> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define ll long long #define REP(i, a, b) for (i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define MD 1000000007 char sep[2] = {' ', '\n'}; int main() { int i, j, k, n, m, l; char s1[210], s2[110]; scanf("%s\n%s", s1, s2); strcat(s1, s1); if (nullptr == strstr(s1, s2)) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
#include <cctype> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define ll long long #define REP(i, a, b) for (i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define MD 1000000007 char sep[2] = {' ', '\n'}; int main() { int i, j, k, n, m, l; char s1[210], s2[110], s3[210]; cin >> s1 >> s2; strcpy(s3, s1); strcat(s3, s1); if (nullptr == strstr(s3, s2)) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
replace
16
20
16
21
0
p02418
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int main() { char str1[201], str2[101]; cin >> str1 >> str2; cout << (strstr(strcat(str1, str1), str2) ? "Yes" : "No") << endl; return 0; }
#include <cstring> #include <iostream> using namespace std; int main() { char test_str[201], search_string[101], copied_test_str[101]; cin >> test_str >> search_string; strcpy(copied_test_str, test_str); strcat(test_str, copied_test_str); cout << (strstr(test_str, search_string) ? "Yes" : "No") << endl; return 0; }
replace
5
8
5
11
0
p02418
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string p, s; cin >> s; cin >> p; for (int i = 0; i < 100; i++) s += s; if (s.find(p) != string::npos) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string p, s; cin >> s; cin >> p; while (s.size() <= 100) s += s; if (s.find(p) != string::npos) cout << "Yes" << endl; else cout << "No" << endl; }
replace
7
8
7
8
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02418
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int a, b; string s, p; cin >> s >> p; s = s + s; a = s.size() * 2 - 1; b = p.size(); for (int i = 0; i < a; i++) { for (int n = 1; n < a; n++) { if (p == s.substr(i, n)) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; }
#include <iostream> #include <string> using namespace std; int main() { int a, b; string s, p; cin >> s >> p; s = s + s; a = s.size() * 2 - 1; b = s.size(); for (int i = 0; i < b; i++) { for (int n = 1; n < a; n++) { if (p == s.substr(i, n)) { cout << "Yes" << endl; return 0; } } } cout << "No" << endl; }
replace
9
11
9
11
0
p02419
C++
Time Limit Exceeded
#include <iostream> #include <string> using namespace std; int main() { string T, S; int count = 0, i; cin >> S; while (T != "END_OF_TEXT") { cin >> T; for (i = 0; i < T.size(); i++) { if (T[i] >= 'A' && T[i] <= 'Z') T[i] += 32; } if (T == S) count++; } cout << count << endl; }
#include <iostream> #include <string> using namespace std; int main() { string T, S; int count = 0, i; cin >> S; while (cin >> T, T != "END_OF_TEXT") { for (i = 0; i < T.size(); i++) { if (T[i] >= 'A' && T[i] <= 'Z') T[i] += 32; } if (T == S) count++; } cout << count << endl; }
replace
9
11
9
10
TLE
p02419
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; char tolower(char ch) { if ('A' <= ch && ch && ch <= 'Z') { return ch - 'A' + 'a'; } else { return ch; } } int main() { int count = 0; string W; cin >> W; string str; while (1) { cin >> str; if (str == "END_PF_TEXT") break; for (int i = 0; i < (int)str.size(); i++) { str[i] = tolower(str[i]); } if (str == W) { count++; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; char tolower(char ch) { if ('A' <= ch && ch && ch <= 'Z') { return ch - 'A' + 'a'; } else { return ch; } } int main() { int count = 0; string W; cin >> W; string str; while (1) { cin >> str; if (str == "END_OF_TEXT") break; for (int i = 0; i < (int)str.size(); i++) { str[i] = tolower(str[i]); } if (str == W) { count++; } } cout << count << endl; return 0; }
replace
16
17
16
17
TLE
p02419
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <cstdio> #include <iostream> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define llong long long #define INF 999999999 #define pb(a) push_back(a) using namespace std; vector<string> split(string str, char delim) { vector<string> res; size_t current = 0, found; while ((found = str.find_first_of(delim, current)) != string::npos) { string tmp = string(str, current, found - current); res.push_back(tmp); current = found + 1; } string tmp = string(str, current, found - current); tmp.replace(tmp.size() - 1, tmp.size(), "\0"); res.push_back(string(str, current, str.size() - current)); return res; } char *StrToUpper(char *s) { char *p; for (p = s; *p; p++) { *p = toupper(*p); } return s; } int main() { char cword[11]; cin >> cword; int cnt = 0; while (1) { char cstr[1001]; cin >> cstr; if (string(cstr).find("END_OF_TEXT") != string::npos) break; string word = StrToUpper(cword); vector<string> vec = split(StrToUpper(cstr), ' '); // transform(word.begin(), word.end(), word.begin(), toupper); // transform(str.begin(), str.end(), str.begin(), toupper); int num = 0; for (int i = 0; i < vec.size(); i++) { if (vec[i] == word) cnt++; } } printf("%d\n", cnt); while (1) { } }
#include <algorithm> #include <cctype> #include <cstdio> #include <iostream> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define llong long long #define INF 999999999 #define pb(a) push_back(a) using namespace std; vector<string> split(string str, char delim) { vector<string> res; size_t current = 0, found; while ((found = str.find_first_of(delim, current)) != string::npos) { string tmp = string(str, current, found - current); res.push_back(tmp); current = found + 1; } string tmp = string(str, current, found - current); tmp.replace(tmp.size() - 1, tmp.size(), "\0"); res.push_back(string(str, current, str.size() - current)); return res; } char *StrToUpper(char *s) { char *p; for (p = s; *p; p++) { *p = toupper(*p); } return s; } int main() { char cword[11]; cin >> cword; int cnt = 0; while (1) { char cstr[1001]; cin >> cstr; if (string(cstr).find("END_OF_TEXT") != string::npos) break; string word = StrToUpper(cword); vector<string> vec = split(StrToUpper(cstr), ' '); // transform(word.begin(), word.end(), word.begin(), toupper); // transform(str.begin(), str.end(), str.begin(), toupper); int num = 0; for (int i = 0; i < vec.size(); i++) { if (vec[i] == word) cnt++; } } printf("%d\n", cnt); }
delete
66
69
66
66
TLE
p02419
C++
Runtime Error
#include <cctype> #include <iostream> using namespace std; #include <cstdio> #include <cstring> #include <string> string Upper(string s) { string t = s; for (int i = 0; s.size(); i++) { t[i] = toupper(s[i]); } return t; } int main() { string W, T; int count = 0; cin >> W; W = Upper(W); while (1) { cin >> T; if (T == "END_OF_TEXT") break; T = Upper(T); if (T == W) count++; } cout << count << "\n"; return 0; }
#include <cctype> #include <iostream> using namespace std; #include <cstdio> #include <cstring> #include <string> string Upper(string s) { string t = s; for (int i = 0; i < s.size(); i++) { t[i] = toupper(s[i]); } return t; } int main() { string W, T; int count = 0; cin >> W; W = Upper(W); while (1) { cin >> T; if (T == "END_OF_TEXT") break; T = Upper(T); if (T == W) count++; } cout << count << "\n"; return 0; }
replace
10
11
10
11
-11
p02419
C++
Time Limit Exceeded
#include <iostream> #include <string> using namespace std; int main() { int ans = 0; string w; cin >> w; for (int i = 0; i < w.size(); i++) { if (isupper(w[i])) { w[i] = tolower(w[i]); } } string t; while (true) { cin >> t; if (t == "END???OF???TEXT") break; for (int j = 0; j < t.size(); j++) { if (isupper(t[j])) { t[j] = tolower(t[j]); } } if (t == w) { ans++; } } cout << ans << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { int ans = 0; string w; cin >> w; for (int i = 0; i < w.size(); i++) { if (isupper(w[i])) { w[i] = tolower(w[i]); } } string t; while (true) { cin >> t; if (t == "END_OF_TEXT") break; for (int j = 0; j < t.size(); j++) { if (isupper(t[j])) { t[j] = tolower(t[j]); } } if (t == w) { ans++; } } cout << ans << endl; return 0; }
replace
15
16
15
16
TLE
p02419
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int cnt = 0, match = 0; string w, t[150]; cin >> w; string tt; int a = 0; while (cin >> tt, tt != "END_OF_TEXT") { t[a] = tt; a++; } for (int j = 0; j < a; j++) { for (int i = 0; i < t[j].size(); i++) { if (w.size() != t[j].size()) { break; } if (32 + w[match] == t[j][i] || w[match] == t[j][i] || w[match] == t[j][i] + 32) { match++; } else { match = 0; } if (match == w.size()) { cnt++; match = 0; } } match = 0; } cout << cnt << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { int cnt = 0, match = 0; string w, t[300]; cin >> w; string tt; int a = 0; while (cin >> tt, tt != "END_OF_TEXT") { t[a] = tt; a++; } for (int j = 0; j < a; j++) { for (int i = 0; i < t[j].size(); i++) { if (w.size() != t[j].size()) { break; } if (32 + w[match] == t[j][i] || w[match] == t[j][i] || w[match] == t[j][i] + 32) { match++; } else { match = 0; } if (match == w.size()) { cnt++; match = 0; } } match = 0; } cout << cnt << endl; return 0; }
replace
5
6
5
6
0
p02419
C++
Runtime Error
// // main.cpp // ITP1-9-A // // Created by h3037153 on 2017/08/28. // Copyright ?? 2017??´ h3037153. All rights reserved. // #include <cctype> #include <iostream> #include <string> using namespace std; int main() { string W, T[100]; int i = 0, counter = 0, ii = 0, len; char ch = {}; cin >> W; while (cin >> T[i]) { if (T[i] == "END_OF_TEXT") { break; } len = T[i].length(); for (ii = 0; ii < len; ii++) { if (isupper(T[i][ii])) { ch = tolower(T[i][ii]); T[i][ii] = ch; } } if (T[i] == W) { counter++; } else i++; } cout << counter << endl; return 0; }
// // main.cpp // ITP1-9-A // // Created by h3037153 on 2017/08/28. // Copyright ?? 2017??´ h3037153. All rights reserved. // #include <cctype> #include <iostream> #include <string> using namespace std; int main() { string W, T[1000]; int i = 0, counter = 0, ii = 0, len; char ch = {}; cin >> W; while (cin >> T[i]) { if (T[i] == "END_OF_TEXT") { break; } len = T[i].length(); for (ii = 0; ii < len; ii++) { if (isupper(T[i][ii])) { ch = tolower(T[i][ii]); T[i][ii] = ch; } } if (T[i] == W) { counter++; } else i++; } cout << counter << endl; return 0; }
replace
12
13
12
13
0
p02419
Python
Runtime Error
import sys s = sys.stdin.read().split() print(s[1:].split().count(s[0]))
import sys s = input().lower() t = sys.stdin.read().lower().split() print(t.count(s))
replace
2
4
2
5
AttributeError: 'list' object has no attribute 'split'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02419/Python/s514815878.py", line 3, in <module> print(s[1:].split().count(s[0])) AttributeError: 'list' object has no attribute 'split'
p02420
C++
Runtime Error
#include <iostream> int main() { std::string str; int m, h; while (true) { std::cin >> str; if (str == "-") break; std::cin >> m; for (int i = 0; i < m; i++) { std::cin >> h; str = str.substr(h) + str.erase(h); } std::cout << str << std::endl; } }
#include <iostream> int main() { std::string str; int m, h; while (true) { std::cin >> str; if (str == "-") break; std::cin >> m; for (int i = 0; i < m; i++) { std::cin >> h; str = str.substr(h) + str.substr(0, h); } std::cout << str << std::endl; } }
replace
14
15
14
15
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::erase: __pos (which is 2) > this->size() (which is 1)
p02420
C++
Time Limit Exceeded
#include <stdio.h> int main() { char cards[200]; char newCards[200]; int m, cardsLen; // int h[100]; int h; while (true) { scanf("%s", cards); if (cards == "-") goto length; cardsLen = 0; while (cards[cardsLen] != '\0') cardsLen++; scanf("%d", &m); for (int i = 0; i < m; i++) { // scanf("%d",&h[i]); scanf("%d", &h); for (int j = 0; j < cardsLen; j++) { newCards[j] = cards[(j + h) % cardsLen]; } for (int j = 0; j < cardsLen; j++) { cards[j] = newCards[j]; } } printf("%s\n", cards); } length: return 0; }
#include <stdio.h> int main() { char cards[200]; char newCards[200]; int m, cardsLen; // int h[100]; int h; while (true) { scanf("%s", cards); if (cards[0] == '-') break; cardsLen = 0; while (cards[cardsLen] != '\0') cardsLen++; scanf("%d", &m); for (int i = 0; i < m; i++) { // scanf("%d",&h[i]); scanf("%d", &h); for (int j = 0; j < cardsLen; j++) { newCards[j] = cards[(j + h) % cardsLen]; } for (int j = 0; j < cardsLen; j++) { cards[j] = newCards[j]; } } printf("%s\n", cards); } length: return 0; }
replace
11
13
11
13
TLE
p02420
C++
Runtime Error
#include <stdio.h> #include <string.h> #define rep(i, a) for (int i = 0; i < a; ++i) int main(void) { char s[250], t[250]; int m, i, j, n, a; while (1) { scanf("%s", s); n = strlen(s); if (n == 1 && s[0] == '-') break; scanf("%d", &m); rep(i, m) { scanf("%d", a); rep(j, a) t[j] = s[j]; t[a] = 0; rep(j, (n - a)) s[j] = s[j + a]; rep(j, a) s[j + n - a] = t[j]; } printf("%s\n", s); } return 0; }
#include <stdio.h> #include <string.h> #define rep(i, a) for (int i = 0; i < a; ++i) int main(void) { char s[250], t[250]; int m, i, j, n, a; while (1) { scanf("%s", s); n = strlen(s); if (n == 1 && s[0] == '-') break; scanf("%d", &m); rep(i, m) { scanf("%d", &a); rep(j, a) t[j] = s[j]; t[a] = 0; rep(j, (n - a)) s[j] = s[j + a]; rep(j, a) s[j + n - a] = t[j]; } printf("%s\n", s); } return 0; }
replace
14
15
14
15
-11
p02420
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string str; int m, h; while (1) { cin >> str >> m; if (str == "-") break; for (int i = 0; i < m; i++) { cin >> h; str = str.substr(h + 1, str.size() - h) + str.substr(0, h); } cout << str << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { string str; int m, h; while (1) { cin >> str >> m; if (str == "-") break; for (int i = 0; i < m; i++) { cin >> h; str = str.substr(h, str.size() - h) + str.substr(0, h); } cout << str << endl; } return 0; }
replace
14
15
14
15
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 5) > this->size() (which is 4)
p02420
C++
Time Limit Exceeded
#include <iostream> #include <string> using namespace std; int main() { string data, data_copy; int m, h; for (;;) { cin >> data; if (data == "_") break; data_copy = data; cin >> m; for (int i = 0; i < m; i++) { cin >> h; for (int j = 0; j < data.length(); j++) { if ((j + 1 - h) <= 0) { data[data.length() - h + j] = data_copy[j]; } else { data[j - h] = data_copy[j]; } } // data?????¨???????????? for (int j = 0; j < data.length(); j++) { data_copy[j] = data[j]; } } //?????£??????????????°??????????????? cout << data << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { string data, data_copy; int m, h; for (;;) { cin >> data; if (data == "-") break; data_copy = data; cin >> m; for (int i = 0; i < m; i++) { cin >> h; for (int j = 0; j < data.length(); j++) { if ((j + 1 - h) <= 0) { data[data.length() - h + j] = data_copy[j]; } else { data[j - h] = data_copy[j]; } } // data?????¨???????????? for (int j = 0; j < data.length(); j++) { data_copy[j] = data[j]; } } //?????£??????????????°??????????????? cout << data << endl; } return 0; }
replace
12
13
12
13
TLE
p02420
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define vvi vector<vector<int>> #define vi vector<int> #define All(X) X.begin(), X.end() #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define pii pair<int, int> #define mp make_pair ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { string s[1000] = {""}; int m[1000] = {0}; int h[1000][1000] = {0}; int i, j = 0; while (1) { cin >> s[i]; if (s[i] == "-") break; cin >> m[i]; for (int k = 0; k < m[i]; ++k) { cin >> h[i][k]; } i++; } i = 0; while (1) { if (s[i] == "-") break; for (int k = 0; k < m[i]; ++k) { for (int l = 0; l < h[i][k]; ++l) { s[i] += s[i][0]; s[i].erase(0, 1); } } cout << s[i] << endl; i++; } }
#include <algorithm> #include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define vvi vector<vector<int>> #define vi vector<int> #define All(X) X.begin(), X.end() #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define pii pair<int, int> #define mp make_pair ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { string s[1000] = {""}; int m[1000] = {0}; int h[1000][1000] = {0}; int i = 0; int j = 0; while (1) { cin >> s[i]; if (s[i] == "-") break; cin >> m[i]; for (int k = 0; k < m[i]; ++k) { cin >> h[i][k]; } i++; } i = 0; while (1) { if (s[i] == "-") break; for (int k = 0; k < m[i]; ++k) { for (int l = 0; l < h[i][k]; ++l) { s[i] += s[i][0]; s[i].erase(0, 1); } } cout << s[i] << endl; i++; } }
replace
29
30
29
31
0
p02420
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define pi M_PI typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef pair<int, int> P; typedef pair<ll, ll> PL; int main() { string s; while (cin >> s && s != "-") { int m, x = 0; while (m--) { int a; cin >> a; x += a; } REP(i, s.length()) { cout << s[(i + x) % s.length()]; } cout << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define pi M_PI typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef pair<int, int> P; typedef pair<ll, ll> PL; int main() { string s; while (cin >> s && s != "-") { int m, x = 0; cin >> m; while (m--) { int a; cin >> a; x += a; } REP(i, s.length()) { cout << s[(i + x) % s.length()]; } cout << endl; } return 0; }
insert
30
30
30
31
TLE
p02420
C++
Runtime Error
#include <stdio.h> int main() { int m, now, temp, tot; char a[101], b[101]; for (int i = 0; i < 101; i++) b[i] = a[i] = '\0'; while (1) { scanf("%s", a); if (a[0] == '-') return 0; now = 0; while (a[now] != '\0') now++; scanf("%d", &m); tot = 0; for (int i = 0; i < m; i++) { scanf("%d", &temp); tot += temp; } temp = tot % now; for (int j = 0; j < temp; j++) b[j] = a[j]; for (int j = temp; j < now; j++) { a[j - temp] = a[j]; } for (int j = 0; j < temp; j++) { a[now - temp + j] = b[j]; } for (int i = 0; i < now; i++) { printf("%c", a[i]); b[i] = a[i] = '\0'; } printf("\n"); } }
#include <stdio.h> int main() { int m, now, temp, tot; char a[1001], b[1001]; for (int i = 0; i < 1001; i++) b[i] = a[i] = '\0'; while (1) { scanf("%s", a); if (a[0] == '-') return 0; now = 0; while (a[now] != '\0') now++; scanf("%d", &m); tot = 0; for (int i = 0; i < m; i++) { scanf("%d", &temp); tot += temp; } temp = tot % now; for (int j = 0; j < temp; j++) b[j] = a[j]; for (int j = temp; j < now; j++) { a[j - temp] = a[j]; } for (int j = 0; j < temp; j++) { a[now - temp + j] = b[j]; } for (int i = 0; i < now; i++) { printf("%c", a[i]); b[i] = a[i] = '\0'; } printf("\n"); } }
replace
3
5
3
5
0
p02420
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int m, h; while (1) { char tmp[400]; string str; cin >> str; if (str == "~") { break; } for (int i = 0; i < str.size(); i++) { tmp[i] = str[i]; tmp[str.size() + i] = str[i]; } cin >> m; int sum = 0; for (int i = 0; i < m; i++) { cin >> h; sum += h; } int count = 0; for (int i = sum % str.size();; i++) { cout << tmp[i]; count++; if (count == str.size()) { break; } } cout << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int m, h; while (1) { char tmp[400]; string str; cin >> str; if (str == "-") { break; } for (int i = 0; i < str.size(); i++) { tmp[i] = str[i]; tmp[str.size() + i] = str[i]; } cin >> m; int sum = 0; for (int i = 0; i < m; i++) { cin >> h; sum += h; } int count = 0; for (int i = sum % str.size();; i++) { cout << tmp[i]; count++; if (count == str.size()) { break; } } cout << endl; } return 0; }
replace
9
10
9
10
-8
p02420
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> int main() { int m, n; std::string str, tes; while (true) { std::cin >> str >> m; if (m == '-') break; for (int a = 0; a < m; a++) { std::cin >> n; tes = str.substr(0, n); str.erase(str.begin(), str.begin() + n); str += tes; } std::cout << str << std::endl; } return 0; }
#include <algorithm> #include <iostream> #include <string> int main() { int m, n; std::string str, tes; while (true) { std::cin >> str >> m; if (str == "-") break; for (int a = 0; a < m; a++) { std::cin >> n; tes = str.substr(0, n); str.erase(str.begin(), str.begin() + n); str += tes; } std::cout << str << std::endl; } return 0; }
replace
9
10
9
10
-11
p02420
C++
Runtime Error
#include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main() { string ch, x; int kai, shu; while (1) { cin >> ch; x = ch; if (ch == "_") break; cin >> kai; for (int i = 0; i < kai; i++) { cin >> shu; for (int j = 0; j < shu; j++) { x[j] = ch[j]; } // cout << ch << endl; for (int j = 0; j < ch.size() - shu; j++) { ch[j] = ch[j + shu]; } for (int j = 0; j < shu; j++) { ch[(ch.size() - shu) + j] = x[j]; } // cout << ch << endl; } cout << ch << endl; } return 0; }
#include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; int main() { string ch, x; int kai, shu; while (1) { cin >> ch; x = ch; if (ch == "-") break; cin >> kai; for (int i = 0; i < kai; i++) { cin >> shu; for (int j = 0; j < shu; j++) { x[j] = ch[j]; } // cout << ch << endl; for (int j = 0; j < ch.size() - shu; j++) { ch[j] = ch[j + shu]; } for (int j = 0; j < shu; j++) { ch[(ch.size() - shu) + j] = x[j]; } // cout << ch << endl; } cout << ch << endl; } return 0; }
replace
12
13
12
13
-11
p02420
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { string card; string right; string left; int n; int m; while (cin >> card, card != "-") { cin >> m; for (int i = 0; i < n; i++) { cin >> m; right = card.substr(0, m); left = card.substr(m); card = left + right; } cout << card << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string card; string right; string left; int n; int m; while (cin >> card, card != "-") { cin >> n; for (int i = 0; i < n; i++) { cin >> m; right = card.substr(0, m); left = card.substr(m); card = left + right; } cout << card << endl; } return 0; }
replace
11
12
11
12
TLE
p02420
C++
Runtime Error
#include <cctype> #include <iostream> #include <string> using namespace std; string shuffle(string str, int h) { string head = str.substr(0, h); string tail = str.substr(h, str.size() - h); return tail + head; } int main() { string cards; int m, h; while (1) { cin >> cards; if (cards == "_") break; cin >> m; for (int i = 0; i < m; i++) { cin >> h; cards = shuffle(cards, h); } cout << cards << endl; } return 0; }
#include <cctype> #include <iostream> #include <string> using namespace std; string shuffle(string str, int h) { string head = str.substr(0, h); string tail = str.substr(h, str.size() - h); return tail + head; } int main() { string cards; int m, h; while (1) { cin >> cards; if (cards == "-") break; cin >> m; for (int i = 0; i < m; i++) { cin >> h; cards = shuffle(cards, h); } cout << cards << endl; } return 0; }
replace
18
19
18
19
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 4) > this->size() (which is 1)
p02420
C++
Runtime Error
#include <cctype> #include <iostream> #include <string> using namespace std; string shuffle(string str, int h) { string head = str.substr(0, h); string tail = str.substr(h, str.size() - h); return tail + head; } int main() { string cards; int m, h; while (1) { cin >> cards; if (cards == "_") break; cin >> m; for (int i = 0; i < m; i++) { cin >> h; cards = shuffle(cards, h); } cout << cards << endl; } return 0; }
#include <cctype> #include <iostream> #include <string> using namespace std; string shuffle(string str, int h) { string head = str.substr(0, h); string tail = str.substr(h, str.size() - h); return tail + head; } int main() { string cards; int m, h; while (1) { cin >> cards; if (cards == "-") break; cin >> m; for (int i = 0; i < m; i++) { cin >> h; cards = shuffle(cards, h); } cout << cards << endl; } return 0; }
replace
17
18
17
18
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 4) > this->size() (which is 1)
p02420
C++
Runtime Error
#include <cstdio> #include <cstring> int main(void) { int i, j; int m[256]; int s[256] = {0}; char c[256][201]; int d[256] = {0}; int k = 0; while (1) { scanf("%s", c[k]); if (strcmp(c[k], "_") == 0) break; while (c[k][d[k]] != '\0') { d[k]++; }; scanf("%d", &m[k]); for (i = 0; i < m[k]; i++) { scanf("%d", &j); s[k] = s[k] + j; }; s[k] = s[k] % d[k]; k++; } for (i = 0; i < k; i++) { for (j = 0; j < d[i]; j++) { c[i][j + d[i]] = c[i][j]; }; for (j = 0; j < d[i]; j++) { printf("%c", c[i][j + s[i]]); }; printf("\n"); }; return 0; }
#include <cstdio> #include <cstring> int main(void) { int i, j; int m[256]; int s[256] = {0}; char c[256][201]; int d[256] = {0}; int k = 0; while (1) { scanf("%s", c[k]); if (strcmp(c[k], "-") == 0) break; while (c[k][d[k]] != '\0') { d[k]++; }; scanf("%d", &m[k]); for (i = 0; i < m[k]; i++) { scanf("%d", &j); s[k] = s[k] + j; }; s[k] = s[k] % d[k]; k++; } for (i = 0; i < k; i++) { for (j = 0; j < d[i]; j++) { c[i][j + d[i]] = c[i][j]; }; for (j = 0; j < d[i]; j++) { printf("%c", c[i][j + s[i]]); }; printf("\n"); }; return 0; }
replace
12
13
12
13
-8
p02420
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string str; int m, h, i; while (cin >> str, str != "-") { cin >> m; for (i = 0; i < m; i++) { cin >> h; str = str.substr(h + 1, str.size() - h) + str.substr(0, h); } cout << str << endl; } }
#include <iostream> #include <string> using namespace std; int main() { string str; int m, h, i; while (cin >> str, str != "-") { cin >> m; for (i = 0; i < m; i++) { cin >> h; str = str.substr(h, str.size() - h) + str.substr(0, h); } cout << str << endl; } }
replace
13
14
13
14
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 5) > this->size() (which is 4)
p02420
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define vvi vector<vector<int>> #define vi vector<int> #define All(X) X.begin(), X.end() #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define pii pair<int, int> #define mp make_pair ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { string s[1000] = {""}; int m[1000] = {0}; int h[1000][1000] = {0}; int i; int j; while (1) { cin >> s[i]; if (s[i] == "-") break; cin >> m[i]; for (int k = 0; k < m[i]; ++k) { cin >> h[i][k]; } i++; } i = 0; while (1) { if (s[i] == "-") break; for (int k = 0; k < m[i]; ++k) { for (int l = 0; l < h[i][k]; ++l) { s[i] += s[i][0]; s[i].erase(0, 1); } } cout << s[i] << endl; i++; } }
#include <algorithm> #include <cmath> #include <complex> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define vvi vector<vector<int>> #define vi vector<int> #define All(X) X.begin(), X.end() #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define pii pair<int, int> #define mp make_pair ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { string s[1000] = {""}; int m[1000] = {0}; int h[1000][1000] = {0}; int i = 0; int j = 0; while (1) { cin >> s[i]; if (s[i] == "-") break; cin >> m[i]; for (int k = 0; k < m[i]; ++k) { cin >> h[i][k]; } i++; } i = 0; while (1) { if (s[i] == "-") break; for (int k = 0; k < m[i]; ++k) { for (int l = 0; l < h[i][k]; ++l) { s[i] += s[i][0]; s[i].erase(0, 1); } } cout << s[i] << endl; i++; } }
replace
29
31
29
31
0
p02420
C++
Runtime Error
#include <cstdio> int main() { char cards[200]; int c, s, i; char t; while (true) { i = 0; scanf("%c", &t); if (t == '-') { return 0; } while (t - 10) { cards[i] = t; i++; scanf("%c", &t); } for (int j = 0; j < i; j++) { cards[j + i] = cards[j]; } scanf("%d", &c); int sum = 0; for (int j = 0; j < c; j++) { scanf("%d", &s); sum += s; } sum %= i; scanf("%c", &t); for (int j = 0; j < i; j++) { printf("%c", cards[j + sum]); } printf("\n"); } }
#include <cstdio> int main() { char cards[400]; int c, s, i; char t; while (true) { i = 0; scanf("%c", &t); if (t == '-') { return 0; } while (t - 10) { cards[i] = t; i++; scanf("%c", &t); } for (int j = 0; j < i; j++) { cards[j + i] = cards[j]; } scanf("%d", &c); int sum = 0; for (int j = 0; j < c; j++) { scanf("%d", &s); sum += s; } sum %= i; scanf("%c", &t); for (int j = 0; j < i; j++) { printf("%c", cards[j + sum]); } printf("\n"); } }
replace
3
4
3
4
0
p02420
C++
Time Limit Exceeded
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { string card, sub; int m, h; while (1) { cin >> card; if (card == "_") break; cin >> m; for (int i = 0; i < m; i++) { cin >> h; sub = card.substr(0, h); card.erase(0, h); card = card + sub; } cout << card << endl; } return 0; }
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { string card, sub; int m, h; while (1) { cin >> card; if (card == "-") break; cin >> m; for (int i = 0; i < m; i++) { cin >> h; sub = card.substr(0, h); card.erase(0, h); card = card + sub; } cout << card << endl; } return 0; }
replace
11
12
11
12
TLE
p02421
C++
Time Limit Exceeded
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; int taro_score = 0, hana_score = 0; while (1) { string taro, hana; cin >> taro >> hana; if (taro > hana) { taro_score += 3; } else if (taro < hana) { hana_score += 3; } else { taro_score++; hana_score++; } } cout << taro_score << " " << hana_score << "\n"; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; int taro_score = 0, hana_score = 0; for (int i = 0; i < n; ++i) { string taro, hana; cin >> taro >> hana; if (taro > hana) { taro_score += 3; } else if (taro < hana) { hana_score += 3; } else { taro_score++; hana_score++; } } cout << taro_score << " " << hana_score << "\n"; return 0; }
replace
8
9
8
9
TLE
p02421
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string> using namespace std; int ps, pt; int sdiff(string sx, string tx) { if (sx == tx) { ps = 1; pt = 1; } else if (sx > tx) { ps = 3; pt = 0; } else { ps = 0; pt = 3; } return 0; } int main(void) { int n, k, is, it; string s[101] = {}, t[101] = {}; cin >> n; is = 0; it = 0; for (k = 1; k <= n; k++) { cin >> s[k] >> t[k]; sdiff(s[k], t[k]); is = is + ps; it = it + pt; } cout << is << " " << it << endl; return 0; }
#include <iostream> #include <stdio.h> #include <string> using namespace std; int ps, pt; int sdiff(string sx, string tx) { if (sx == tx) { ps = 1; pt = 1; } else if (sx > tx) { ps = 3; pt = 0; } else { ps = 0; pt = 3; } return 0; } int main(void) { int n, k, is, it; string s[1001] = {}, t[1001] = {}; cin >> n; is = 0; it = 0; for (k = 1; k <= n; k++) { cin >> s[k] >> t[k]; sdiff(s[k], t[k]); is = is + ps; it = it + pt; } cout << is << " " << it << endl; return 0; }
replace
23
24
23
24
0
p02421
C++
Runtime Error
#include <iostream> #include <string.h> using namespace std; int main() { int n, ts = 0, hs = 0; char *t, *h; cin >> n; while (n--) { cin >> t >> h; if (strcmp(t, h) > 0) ts += 3; else if (strcmp(t, h) < 0) hs += 3; else { ts += 1; hs += 1; } } cout << ts << ' ' << hs << endl; return 0; }
#include <iostream> #include <string.h> using namespace std; int main() { int n, ts = 0, hs = 0; char t[100], h[100]; cin >> n; while (n--) { cin >> t >> h; if (strcmp(t, h) > 0) ts += 3; else if (strcmp(t, h) < 0) hs += 3; else { ts += 1; hs += 1; } } cout << ts << ' ' << hs << endl; return 0; }
replace
6
7
6
7
-11
p02422
C++
Runtime Error
#include <algorithm> #include <array> #include <cstdio> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> #define _USE_MATH_DEFINES #include <math.h> #include <unordered_map> #define min(a, b) (a) > (b) ? (b) : (a) #define max(a, b) (a) > (b) ? (a) : (b) using namespace std; int main() { string str; int n; cin >> str >> n; for (int i = 0; i < n; i++) { string command; cin >> command; if (command == "replace") { int f, t; string newStr; cin >> f >> t >> newStr; str.replace(f, t, newStr); } else if (command == "reverse") { int f, t; cin >> f >> t; reverse(str.begin() + f, str.begin() + t + 1); } else if (command == "print") { int f, t; cin >> f >> t; for (int j = f; j <= t; j++) { printf("%c", str[j]); } printf("\n"); } } return 0; }
#include <algorithm> #include <array> #include <cstdio> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> #define _USE_MATH_DEFINES #include <math.h> #include <unordered_map> #define min(a, b) (a) > (b) ? (b) : (a) #define max(a, b) (a) > (b) ? (a) : (b) using namespace std; int main() { string str; int n; cin >> str >> n; for (int i = 0; i < n; i++) { string command; cin >> command; if (command == "replace") { int f, t; string newStr; cin >> f >> t >> newStr; str.replace(f, t - f + 1, newStr.c_str()); } else if (command == "reverse") { int f, t; cin >> f >> t; reverse(str.begin() + f, str.begin() + t + 1); } else if (command == "print") { int f, t; cin >> f >> t; for (int j = f; j <= t; j++) { printf("%c", str[j]); } printf("\n"); } } return 0; }
replace
32
33
32
33
0
p02422
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string strInput, strTemp; int nCount; int i, j; cin >> strInput; cin >> nCount; while (nCount--) { cin >> strTemp >> i >> j; if ("reverse" == strTemp) { reverse(strInput.begin() + i, strInput.begin() + j + 1); // j+1 } else if ("replace" == strTemp) { cin >> strTemp; strInput = strInput.replace(i, j, strTemp); } else { cout << strInput.substr(i, j - i + 1) << endl; } } // system("pause"); return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string strInput, strTemp; int nCount; int i, j; cin >> strInput; cin >> nCount; while (nCount--) { cin >> strTemp >> i >> j; if ("reverse" == strTemp) { reverse(strInput.begin() + i, strInput.begin() + j + 1); // j+1 } else if ("replace" == strTemp) { cin >> strTemp; for (int ii = 0; ii < j - i + 1; ii++) { strInput[i + ii] = strTemp[ii]; } } else { cout << strInput.substr(i, j - i + 1) << endl; } } // system("pause"); return 0; }
replace
17
18
17
20
0
p02422
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { char str_c[1001]; scanf("%s", str_c); string str(str_c); int num_q; scanf("%d", &num_q); int i, j; char cmd_c[100]; string cmd; int a, b; char repl_c[1001]; string repl; string line; i = 0; string new_str; while (1) { getline(cin, line); if (line == "") continue; else i++; sscanf(line.c_str(), "%s", cmd_c); cmd = string(cmd_c); if (cmd == "replace") { sscanf(line.c_str(), "%s %d %d %s", cmd_c, &a, &b, repl_c); repl = string(repl_c); str.replace(a, b, repl); } else { sscanf(line.c_str(), "%s %d %d", cmd_c, &a, &b); if (cmd == "reverse") { new_str = string(str); for (j = a; j <= b; j++) { new_str[j] = str[b + a - j]; } str = string(new_str); // printf("-> %s\n", str.c_str()); } else { cout << str.substr(a, b - a + 1) << endl; } } if (i >= num_q) { break; } } return 0; }
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { char str_c[1001]; scanf("%s", str_c); string str(str_c); int num_q; scanf("%d", &num_q); int i, j; char cmd_c[100]; string cmd; int a, b; char repl_c[1001]; string repl; string line; i = 0; string new_str; while (1) { getline(cin, line); if (line == "") continue; else i++; sscanf(line.c_str(), "%s", cmd_c); cmd = string(cmd_c); if (cmd == "replace") { sscanf(line.c_str(), "%s %d %d %s", cmd_c, &a, &b, repl_c); repl = string(repl_c); str.replace(a, b - a + 1, repl); } else { sscanf(line.c_str(), "%s %d %d", cmd_c, &a, &b); if (cmd == "reverse") { new_str = string(str); for (j = a; j <= b; j++) { new_str[j] = str[b + a - j]; } str = string(new_str); // printf("-> %s\n", str.c_str()); } else { cout << str.substr(a, b - a + 1) << endl; } } if (i >= num_q) { break; } } return 0; }
replace
35
36
35
36
0
p02422
C++
Runtime Error
#include <algorithm> #include <stdio.h> using namespace std; void print(char str[], int a, int b) { for (int i = a; i <= b; i++) printf("%c", str[i]); printf("\n"); } void replace(char str[], char p[], int a, int b) { int p_length = b - a + 1; for (int i = 0; i < p_length; i++) str[a + i] = p[i]; } void reverse(char str[], int a, int b) { int left = a, right = b; while (left < right) { swap(str[left++], str[right--]); } } int main() { char str[1001], p[101], order[8]; int q, a, b; scanf("%s", str); scanf("%d", &q); for (int i = 0; i < q; i++) { scanf("%s %d %d", order, &a, &b); switch (order[2]) { case 'i': print(str, a, b); break; case 'v': reverse(str, a, b); break; case 'p': scanf("%s", p); replace(str, p, a, b); break; } } }
#include <algorithm> #include <stdio.h> using namespace std; void print(char str[], int a, int b) { for (int i = a; i <= b; i++) printf("%c", str[i]); printf("\n"); } void replace(char str[], char p[], int a, int b) { int p_length = b - a + 1; for (int i = 0; i < p_length; i++) str[a + i] = p[i]; } void reverse(char str[], int a, int b) { int left = a, right = b; while (left < right) { swap(str[left++], str[right--]); } } int main() { char str[1001], p[1001], order[8]; int q, a, b; scanf("%s", str); scanf("%d", &q); for (int i = 0; i < q; i++) { scanf("%s %d %d", order, &a, &b); switch (order[2]) { case 'i': print(str, a, b); break; case 'v': reverse(str, a, b); break; case 'p': scanf("%s", p); replace(str, p, a, b); break; } } }
replace
25
26
25
26
0
p02422
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; #define FOR(i, a, b) for (int i = int(a); i < int(b); ++i) #define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) int q; int main() { int a, b; string str, q_str, m_str; cin >> str; cin >> q; REP(i, q) { cin >> q_str; cin >> a >> b; if (q_str == "print") { cout << str.substr(a, b - a + 1) << endl; } else if (q_str == "replace") { cin >> q_str; m_str = str.erase(a, b); str = m_str.insert(a, q_str); } else { reverse(str.begin() + a, str.begin() + b + 1); } // cout << str << endl; } return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; #define FOR(i, a, b) for (int i = int(a); i < int(b); ++i) #define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) int q; int main() { int a, b; string str, q_str, m_str; cin >> str; cin >> q; REP(i, q) { cin >> q_str; cin >> a >> b; if (q_str == "print") { cout << str.substr(a, b - a + 1) << endl; } else if (q_str == "replace") { cin >> q_str; m_str = str.erase(a, b - a + 1); str = m_str.insert(a, q_str); } else { reverse(str.begin() + a, str.begin() + b + 1); } // cout << str << endl; } return 0; }
replace
25
26
25
26
0
p02422
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main(void) { string str, ans[100], p, ex; int a, b, q, cou = 0; char c; cin >> str; cin >> q; for (int i = 0; i < q; i++) { cin >> ex; cin >> a >> b; if (ex == "print") { ans[cou] = str.substr(a, (b - a) + 1); cou++; } if (ex == "reverse") { for (int j = 0; j < (b - a + 1) / 2; j++) { c = str[a + j]; str[a + j] = str[b - j]; str[b - j] = c; } } if (ex == "replace") { cin >> p; str = str.replace(a, b, p); } } for (int i = 0; i < cou; i++) { cout << ans[i] << endl; } }
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main(void) { string str, ans[100], p, ex; int a, b, q, cou = 0; char c; cin >> str; cin >> q; for (int i = 0; i < q; i++) { cin >> ex; cin >> a >> b; if (ex == "print") { ans[cou] = str.substr(a, (b - a) + 1); cou++; } if (ex == "reverse") { for (int j = 0; j < (b - a + 1) / 2; j++) { c = str[a + j]; str[a + j] = str[b - j]; str[b - j] = c; } } if (ex == "replace") { cin >> p; str = str.replace(a, (b - a) + 1, p); } } for (int i = 0; i < cou; i++) { cout << ans[i] << endl; } }
replace
26
27
26
27
0
p02422
C++
Runtime Error
// Lec09-D Transformation #include <algorithm> #include <iostream> #include <string> int main() { static const std::string pri = "print", rev = "reverse", rep = "replace"; std::string str, comm, p; std::cin >> str; int q, a, b; for (std::cin >> q; q; q--) { std::cin >> comm >> a >> b; if (pri == comm) { for (; a <= b; a++) std::cout << str[a]; std::cout << std::endl; } else if (rev == comm) std::reverse(str.begin() + a, str.begin() + b + 1); else if (rep == comm) { std::cin >> p; str.replace(a, b, p, 0, b - a + 1); } } return 0; }
// Lec09-D Transformation #include <algorithm> #include <iostream> #include <string> int main() { static const std::string pri = "print", rev = "reverse", rep = "replace"; std::string str, comm, p; std::cin >> str; int q, a, b; for (std::cin >> q; q; q--) { std::cin >> comm >> a >> b; if (pri == comm) { for (; a <= b; a++) std::cout << str[a]; std::cout << std::endl; } else if (rev == comm) std::reverse(str.begin() + a, str.begin() + b + 1); else if (rep == comm) { std::cin >> p; str.replace(a, b - a + 1, p); } } return 0; }
replace
19
20
19
20
0
p02422
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string A; int x, y; while (cin >> A) { int n; cin >> n; string Action; for (int i = 0; i < n; i++) { cin >> Action; if (Action == "replace") { string replaces; cin >> x >> y >> replaces; A.replace(x, y, replaces); } else if (Action == "reverse") { cin >> x >> y; reverse(A.begin() + x, A.begin() + y + 1); } else { cin >> x >> y; cout << A.substr(x, y - x + 1) << "\n"; } } } return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string A; int x, y; while (cin >> A) { int n; cin >> n; string Action; for (int i = 0; i < n; i++) { cin >> Action; if (Action == "replace") { string replaces; cin >> x >> y >> replaces; A.replace(x, y - x + 1, replaces); } else if (Action == "reverse") { cin >> x >> y; reverse(A.begin() + x, A.begin() + y + 1); } else { cin >> x >> y; cout << A.substr(x, y - x + 1) << "\n"; } } } return 0; }
replace
26
27
26
27
0
p02422
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; int main(void) { string str, moji, m; int q = 0; cin >> str; cin >> q; for (int i = 0; i < q; i++) { int a = 0, b = 0; cin >> moji >> a >> b; if (moji == "print") { str = str.substr(a, b - a + 1); cout << str << endl; } else if (moji == "reverse") { string str2 = str.substr(a, b - a + 1); reverse(str2.begin(), str2.end()); str = str.replace(a, b - a + 1, str2); } else if (moji == "replace") { cin >> m; str = str.replace(a, b - a + 1, m); } } return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main(void) { string str, moji, m; int q = 0; cin >> str; cin >> q; for (int i = 0; i < q; i++) { int a = 0, b = 0; cin >> moji >> a >> b; if (moji == "print") { cout << str.substr(a, b - a + 1) << endl; } else if (moji == "reverse") { string str2 = str.substr(a, b - a + 1); reverse(str2.begin(), str2.end()); str = str.replace(a, b - a + 1, str2); } else if (moji == "replace") { cin >> m; str = str.replace(a, b - a + 1, m); } } return 0; }
replace
13
15
13
14
0
p02422
C++
Runtime Error
/** * ??????????????? ????????? str ?????????????????????????????????????????????????????????????????°???????????????????????????????????????????????\?????????????????????????????§?????? print a b: str ??? a ??????????????? b ??????????????§?????????????????? reverse a b: str ??? a ??????????????? b ??????????????§????????????????????? replace a b p: str ??? a ??????????????? b ??????????????§??? p ????????????????????? ????????§??????????????? str ????????????????????? 0 ???????????¨???????????? Input 1 ?????????????????? str ????????????????????????str ?????±?°????????????????????????????2 ????????????????????° q ?????????????????????????¶???? q ??????????????????????¨??????¢?????§????????????????????? Output ??? print ???????????¨??????????????????????????????????????????????????? Constraints 1???str????????????1000 1???q???100 0???a???b<str????????? replace ????????§??? b???a+1=p????????? Sample Input 1 abcde 3 replace 1 3 xyz reverse 0 2 print 1 4 Sample Output 1 xaze Sample Input 2 xyz 3 print 0 2 replace 0 2 abc print 0 2 Sample Output 2 xyz abc */ #include <algorithm> #include <iostream> #include <sstream> int main(int argc, char const *argv[]) { std::string Source; std::string Param; unsigned short q = 0; std::istringstream iss; getline(std::cin, Source); getline(std::cin, Param); iss.str(Param); iss >> q; iss.clear(); for (size_t i = 0; i < q; i++) { std::string Command, Arg3; unsigned short Arg1, Arg2; getline(std::cin, Param); iss.str(Param); iss >> Command; if (Command == "print") { iss >> Arg1 >> Arg2; Source = Source.substr(Arg1, Arg2 - Arg1 + 1); std::cout << Source << std::endl; } else if (Command == "reverse") { iss >> Arg1 >> Arg2; std::reverse(Source.begin() + Arg1, Source.begin() + Arg2 + 1); } else if (Command == "replace") { iss >> Arg1 >> Arg2 >> Arg3; Source.replace(Arg1, Arg2 - Arg1 + 1, Arg3); } iss.clear(); } return 0; }
/** * ??????????????? ????????? str ?????????????????????????????????????????????????????????????????°???????????????????????????????????????????????\?????????????????????????????§?????? print a b: str ??? a ??????????????? b ??????????????§?????????????????? reverse a b: str ??? a ??????????????? b ??????????????§????????????????????? replace a b p: str ??? a ??????????????? b ??????????????§??? p ????????????????????? ????????§??????????????? str ????????????????????? 0 ???????????¨???????????? Input 1 ?????????????????? str ????????????????????????str ?????±?°????????????????????????????2 ????????????????????° q ?????????????????????????¶???? q ??????????????????????¨??????¢?????§????????????????????? Output ??? print ???????????¨??????????????????????????????????????????????????? Constraints 1???str????????????1000 1???q???100 0???a???b<str????????? replace ????????§??? b???a+1=p????????? Sample Input 1 abcde 3 replace 1 3 xyz reverse 0 2 print 1 4 Sample Output 1 xaze Sample Input 2 xyz 3 print 0 2 replace 0 2 abc print 0 2 Sample Output 2 xyz abc */ #include <algorithm> #include <iostream> #include <sstream> int main(int argc, char const *argv[]) { std::string Source; std::string Param; unsigned short q = 0; std::istringstream iss; getline(std::cin, Source); getline(std::cin, Param); iss.str(Param); iss >> q; iss.clear(); for (size_t i = 0; i < q; i++) { std::string Command, Arg3; unsigned short Arg1, Arg2; getline(std::cin, Param); iss.str(Param); iss >> Command; if (Command == "print") { iss >> Arg1 >> Arg2; std::string Dest; Dest = Source.substr(Arg1, Arg2 - Arg1 + 1); std::cout << Dest << std::endl; } else if (Command == "reverse") { iss >> Arg1 >> Arg2; std::reverse(Source.begin() + Arg1, Source.begin() + Arg2 + 1); } else if (Command == "replace") { iss >> Arg1 >> Arg2 >> Arg3; Source.replace(Arg1, Arg2 - Arg1 + 1, Arg3); } iss.clear(); } return 0; }
replace
74
76
74
77
0
p02422
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { string s; cin >> s; int q; cin >> q; rep(i, q) { string t; cin >> t; if (t == "print") { int a, b; cin >> a >> b; cout << s.substr(a, b - a + 1) << endl; } if (t == "reverse") { int a, b; cin >> a >> b; reverse(s.begin() + a, s.begin() + b + 1); } if (t == "replace") { int a, b; string p; cin >> a >> b >> p; s.replace(a, b, p); } } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { string s; cin >> s; int q; cin >> q; rep(i, q) { string t; cin >> t; if (t == "print") { int a, b; cin >> a >> b; cout << s.substr(a, b - a + 1) << endl; } if (t == "reverse") { int a, b; cin >> a >> b; reverse(s.begin() + a, s.begin() + b + 1); } if (t == "replace") { int a, b; string p; cin >> a >> b >> p; s.replace(a, b - a + 1, p); } } }
replace
26
27
26
27
0
p02422
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) int main() { string str, W, p; long long int q, a, b; cin >> str >> q; REP(i, q) { cin >> W >> a >> b; if (W == "print") { string c(str, a, b - a + 1); cout << c << "\n"; } else if (W == "reverse") { reverse(str.begin() + a, str.begin() + b + 1); } else if (W == "replace") { cin >> p; str.replace(a, b, p); } } return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) int main() { string str, W, p; long long int q, a, b; cin >> str >> q; REP(i, q) { cin >> W >> a >> b; if (W == "print") { string c(str, a, b - a + 1); cout << c << "\n"; } else if (W == "reverse") { reverse(str.begin() + a, str.begin() + b + 1); } else if (W == "replace") { cin >> p; str.replace(a, b - a + 1, p); } } return 0; }
replace
22
23
22
23
0
p02422
C++
Runtime Error
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n; string str, s1; string order; int a, b; cin >> str; cin >> n; for (int i = 0; i < n; i++) { cin >> order >> a >> b; if (order == "print") { for (int i = a; i <= b; i++) { cout << str[i]; } cout << "\n"; } else if (order == "reverse") { for (int i = a, j = b; i < j; i++, j--) swap(str[i], str[j]); } else if (order == "replace") { cin >> s1; str.replace(a, b, s1); } } return 0; }
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n; string str, s1; string order; int a, b; cin >> str; cin >> n; for (int i = 0; i < n; i++) { cin >> order >> a >> b; if (order == "print") { for (int i = a; i <= b; i++) { cout << str[i]; } cout << "\n"; } else if (order == "reverse") { for (int i = a, j = b; i < j; i++, j--) swap(str[i], str[j]); } else if (order == "replace") { cin >> s1; str.replace(a, b - a + 1, s1); } } return 0; }
replace
25
26
25
26
0
p02422
C++
Runtime Error
#include <cctype> #include <iostream> #include <string> using namespace std; int main() { int q, num1, num2; string str, str2, str3; // str1=最初の文字列 str2=条件当てはめる cin >> str >> q; for (int i = 0; i < q; i++) { cin >> str2 >> num1 >> num2; if (str2 == "replace") { cin >> str3; str = str.replace(num1, num2, str3); } else if (str2 == "reverse") { while (num1 <= num2) { char tmp; tmp = str[num1]; str[num1] = str[num2]; str[num2] = tmp; num1++; num2--; } } else if (str2 == "print") { cout << str.substr(num1, num2 - num1 + 1) << endl; } } return 0; }
#include <cctype> #include <iostream> #include <string> using namespace std; int main() { int q, num1, num2; string str, str2, str3; // str1=最初の文字列 str2=条件当てはめる cin >> str >> q; for (int i = 0; i < q; i++) { cin >> str2 >> num1 >> num2; if (str2 == "replace") { cin >> str3; str = str.replace(num1, num2 - num1 + 1, str3); } else if (str2 == "reverse") { while (num1 <= num2) { char tmp; tmp = str[num1]; str[num1] = str[num2]; str[num2] = tmp; num1++; num2--; } } else if (str2 == "print") { cout << str.substr(num1, num2 - num1 + 1) << endl; } } return 0; }
replace
13
14
13
14
0
p02422
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; int q; int a, b; cin >> s; cin >> q; string order, str; for (int i = 0; i < q; i++) { cin >> order; if (order == "replace") { cin >> a >> b >> str; s.replace(a, b, str); } else if (order == "reverse") { cin >> a >> b; reverse(s.begin() + a, s.begin() + b + 1); } else if (order == "print") { cin >> a >> b; for (int i = a; i <= b; i++) { printf("%c", s[i]); } printf("\n"); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int q; int a, b; cin >> s; cin >> q; string order, str; for (int i = 0; i < q; i++) { cin >> order; if (order == "replace") { cin >> a >> b >> str; s.replace(a, str.size(), str); } else if (order == "reverse") { cin >> a >> b; reverse(s.begin() + a, s.begin() + b + 1); } else if (order == "print") { cin >> a >> b; for (int i = a; i <= b; i++) { printf("%c", s[i]); } printf("\n"); } } return 0; }
replace
19
20
19
20
0
p02422
C++
Runtime Error
#include <cstdio> int main() { char str[1001]; char com[8]; int l = 0; int a, b; int q; char c; scanf("%s", &str); scanf("%d", &q); for (int i = 0; i < q; i++) { scanf("%s %d %d", &com, &a, &b); if (com[2] == 'i') { for (int i = a; i <= b; i++) { printf("%c", str[i]); } printf("\n"); } else if (com[2] == 'v') { char t; for (int i = 0; i < ((b - a + 1) / 2); i++) { t = str[a + i]; str[a + i] = str[b - i]; str[b - i] = t; } } else { char r[100]; scanf("%s", &r); for (int j = a; j <= b; j++) { str[j] = r[j - a]; } } } return 0; }
#include <cstdio> int main() { char str[1001]; char com[8]; int l = 0; int a, b; int q; char c; scanf("%s", &str); scanf("%d", &q); for (int i = 0; i < q; i++) { scanf("%s %d %d", &com, &a, &b); if (com[2] == 'i') { for (int i = a; i <= b; i++) { printf("%c", str[i]); } printf("\n"); } else if (com[2] == 'v') { char t; for (int i = 0; i < ((b - a + 1) / 2); i++) { t = str[a + i]; str[a + i] = str[b - i]; str[b - i] = t; } } else { char r[1001]; scanf("%s", &r); for (int j = a; j <= b; j++) { str[j] = r[j - a]; } } } return 0; }
replace
28
29
28
29
0
p02422
C++
Runtime Error
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> int main(void) { std::string str; int a; int b; int q; std::string start = ""; std::string sub = ""; std::string end = ""; std::string s = ""; std::cin >> str >> q; for (int i = 0; i < q; i++) { std::string order; std::cin >> order; std::cin >> a >> b; start = str.substr(0, a); sub = str.substr(a, b - a + 1); end = str.substr(b + 1, str.size() - b); if (order == "replace") { s = ""; std::cin >> s; str = start + s + end; } else if (order == "reverse") { std::reverse(sub.begin(), sub.end()); str = start + sub + end; } else if (order == "print") { str = sub; std::cout << str << std::endl; } } return EXIT_SUCCESS; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> int main(void) { std::string str; int a; int b; int q; std::string start = ""; std::string sub = ""; std::string end = ""; std::string s = ""; std::cin >> str >> q; for (int i = 0; i < q; i++) { std::string order; std::cin >> order; std::cin >> a >> b; start = str.substr(0, a); sub = str.substr(a, b - a + 1); end = str.substr(b + 1, str.size() - b); if (order == "replace") { s = ""; std::cin >> s; str = start + s + end; } else if (order == "reverse") { std::reverse(sub.begin(), sub.end()); str = start + sub + end; } else if (order == "print") { std::cout << sub << std::endl; } else { } } return EXIT_SUCCESS; }
replace
32
34
32
34
0
p02422
C++
Runtime Error
#include <iostream> void p(char *str, int a, int b) { for (int i = a; i <= b; i++) std::cout << str[i]; std::cout << std::endl; } void replace(char *str, int a, int b, char *replace_str) { for (int i = a; i <= b; i++) str[i] = replace_str[i - a]; } void reverse(char *str, int a, int b) { char temp; for (int i = 0; i < (b - a + 1) / 2; i++) { temp = str[a + i]; str[a + i] = str[b - i]; str[b - i] = temp; } } int main() { char str[100], replace_str[100], command[100]; int q, a, b; std::cin >> str >> q; for (int i = 0; i < q; i++) { std::cin >> command >> a >> b; // std::cout << str << "\n\n"; switch (command[2]) { case 'p': std::cin >> replace_str; replace(str, a, b, replace_str); break; case 'v': reverse(str, a, b); break; case 'i': p(str, a, b); break; } // std::cout << command << " " << a << " " << b << std::endl; // std::cout << str << std::endl;; } return 0; }
#include <iostream> void p(char *str, int a, int b) { for (int i = a; i <= b; i++) std::cout << str[i]; std::cout << std::endl; } void replace(char *str, int a, int b, char *replace_str) { for (int i = a; i <= b; i++) str[i] = replace_str[i - a]; } void reverse(char *str, int a, int b) { char temp; for (int i = 0; i < (b - a + 1) / 2; i++) { temp = str[a + i]; str[a + i] = str[b - i]; str[b - i] = temp; } } int main() { char str[1000], replace_str[1000], command[100]; int q, a, b; std::cin >> str >> q; for (int i = 0; i < q; i++) { std::cin >> command >> a >> b; // std::cout << str << "\n\n"; switch (command[2]) { case 'p': std::cin >> replace_str; replace(str, a, b, replace_str); break; case 'v': reverse(str, a, b); break; case 'i': p(str, a, b); break; } // std::cout << command << " " << a << " " << b << std::endl; // std::cout << str << std::endl;; } return 0; }
replace
23
24
23
24
0
p02422
C++
Runtime Error
/* * Transformation.cpp * * Created on: 2014/08/04 * Author: WanWan1985 */ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // for util #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define PB push_back #define MP make_pair #define CL clear #define EXIT (0) typedef unsigned int u_int; typedef long long ll; #define COMMAND_REPLACE "replace" #define COMMAND_REPLACE_NUM (7) #define COMMAND_REVERSE "reverse" #define COMMAND_REVERSE_NUM (7) #define COMMAND_PRINT "print" #define COMMAND_PRINT_NUM (5) void command(string &a_rstrTargetWord, string strCommand); int main(void) { // 入力 string strTargetWord; cin >> strTargetWord; int iCommandNum = 0; cin >> iCommandNum; vector<string> vecCommand; int iCount = 0; while (1) { string strCommand; getline(cin, strCommand); vecCommand.PB(strCommand); if (iCommandNum == iCount) { break; } iCount++; } // 実行 REP(i, vecCommand.size()) { command(strTargetWord, vecCommand.at(i)); } return EXIT; } void command(string &a_rstrTargetWord, string strCommand) { string::size_type pos = strCommand.find(COMMAND_REPLACE, 0); if (pos != string::npos) { pos = strCommand.find(" ", COMMAND_REPLACE_NUM + 1); int iVal1 = atoi( strCommand .substr(COMMAND_REPLACE_NUM + 1, pos - (COMMAND_REPLACE_NUM + 1)) .c_str()); string::size_type tmppos = strCommand.find(" ", pos + 1); int iVal2 = atoi(strCommand.substr(pos + 1, tmppos - pos - 1).c_str()); string strWord = strCommand.substr(tmppos + 1, strCommand.size()); a_rstrTargetWord.replace(iVal1, iVal2 - iVal1 + 1, strWord); return; } pos = strCommand.find(COMMAND_REVERSE, 0); if (pos != string::npos) { pos = strCommand.find(" ", COMMAND_REVERSE_NUM + 1); int iVal1 = atoi( strCommand .substr(COMMAND_REVERSE_NUM + 1, pos - (COMMAND_REVERSE_NUM + 1)) .c_str()); string::size_type tmppos = strCommand.find(" ", pos + 1); int iVal2 = atoi(strCommand.substr(pos + 1, tmppos - pos - 1).c_str()); reverse(&a_rstrTargetWord.at(iVal1), &a_rstrTargetWord.at(iVal2 + 1)); return; } pos = strCommand.find(COMMAND_PRINT, 0); if (pos != string::npos) { pos = strCommand.find(" ", COMMAND_PRINT_NUM + 1); int iVal1 = atoi( strCommand.substr(COMMAND_PRINT_NUM + 1, pos - (COMMAND_PRINT_NUM + 1)) .c_str()); string::size_type tmppos = strCommand.find(" ", pos + 1); int iVal2 = atoi(strCommand.substr(pos, tmppos - pos - 1).c_str()); cout << a_rstrTargetWord.substr(iVal1, iVal2 - iVal1 + 1) << endl; return; } }
/* * Transformation.cpp * * Created on: 2014/08/04 * Author: WanWan1985 */ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // for util #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define PB push_back #define MP make_pair #define CL clear #define EXIT (0) typedef unsigned int u_int; typedef long long ll; #define COMMAND_REPLACE "replace" #define COMMAND_REPLACE_NUM (7) #define COMMAND_REVERSE "reverse" #define COMMAND_REVERSE_NUM (7) #define COMMAND_PRINT "print" #define COMMAND_PRINT_NUM (5) void command(string &a_rstrTargetWord, string strCommand); int main(void) { // 入力 string strTargetWord; cin >> strTargetWord; int iCommandNum = 0; cin >> iCommandNum; vector<string> vecCommand; int iCount = 0; while (1) { string strCommand; getline(cin, strCommand); vecCommand.PB(strCommand); if (iCommandNum == iCount) { break; } iCount++; } // 実行 REP(i, vecCommand.size()) { command(strTargetWord, vecCommand.at(i)); } return EXIT; } void command(string &a_rstrTargetWord, string strCommand) { string::size_type pos = strCommand.find(COMMAND_REPLACE, 0); if (pos != string::npos) { pos = strCommand.find(" ", COMMAND_REPLACE_NUM + 1); int iVal1 = atoi( strCommand .substr(COMMAND_REPLACE_NUM + 1, pos - (COMMAND_REPLACE_NUM + 1)) .c_str()); string::size_type tmppos = strCommand.find(" ", pos + 1); int iVal2 = atoi(strCommand.substr(pos + 1, tmppos - pos - 1).c_str()); string strWord = strCommand.substr(tmppos + 1, strCommand.size()); a_rstrTargetWord.replace(iVal1, iVal2 - iVal1 + 1, strWord); return; } pos = strCommand.find(COMMAND_REVERSE, 0); if (pos != string::npos) { pos = strCommand.find(" ", COMMAND_REVERSE_NUM + 1); int iVal1 = atoi( strCommand .substr(COMMAND_REVERSE_NUM + 1, pos - (COMMAND_REVERSE_NUM + 1)) .c_str()); string::size_type tmppos = strCommand.find(" ", pos + 1); int iVal2 = atoi(strCommand.substr(pos + 1, tmppos - pos - 1).c_str()); reverse(&a_rstrTargetWord[iVal1], &a_rstrTargetWord[iVal2 + 1]); return; } pos = strCommand.find(COMMAND_PRINT, 0); if (pos != string::npos) { pos = strCommand.find(" ", COMMAND_PRINT_NUM + 1); int iVal1 = atoi( strCommand.substr(COMMAND_PRINT_NUM + 1, pos - (COMMAND_PRINT_NUM + 1)) .c_str()); string::size_type tmppos = strCommand.find(" ", pos + 1); int iVal2 = atoi(strCommand.substr(pos, tmppos - pos - 1).c_str()); cout << a_rstrTargetWord.substr(iVal1, iVal2 - iVal1 + 1) << endl; return; } }
replace
99
100
99
100
0
p02422
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string str, com, p; int q, a, b; cin >> str >> q; for (int i = 0; i < q; i++) { cin >> com >> a >> b; if (com == "print") { cout << str.substr(a, b - a + 1) << endl; } else if (com == "reverse") { string tmp = str.substr(a, b - a + 1); int n = tmp.size(); for (int j = 0; i < n; j++) str[j + a] = tmp[n - j - 1]; } else if (com == "replace") { cin >> p; str = str.replace(a, b - a + 1, p); } } return 0; }
#include <iostream> #include <string> using namespace std; int main() { string str, com, p; int q, a, b; cin >> str >> q; for (int i = 0; i < q; i++) { cin >> com >> a >> b; if (com == "print") { cout << str.substr(a, b - a + 1) << endl; } else if (com == "reverse") { string tmp = str.substr(a, b - a + 1); int n = tmp.size(); for (int j = 0; j < n; j++) str[j + a] = tmp[n - j - 1]; } else if (com == "replace") { cin >> p; str = str.replace(a, b - a + 1, p); } } return 0; }
replace
17
18
17
18
-11
p02422
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int a, b; string which, p; string str; int y; cin >> str; cin >> y; for (int i = 0; i < y; i++) { cin >> which >> a >> b; if (which == "print") { str = str.substr(a, b - a + 1); cout << str << endl; } else if (which == "replace") { cin >> p; str = str.replace(a, b - a + 1, p); } else if (which == "reverse") { string tmp = str.substr(a, b - a + 1); int n = tmp.size(); for (int i = 0; i < n; i++) { str[a + i] = tmp[n - i - 1]; } } } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int a, b; string which, p; string str; int y; cin >> str; cin >> y; for (int i = 0; i < y; i++) { cin >> which >> a >> b; if (which == "print") cout << str.substr(a, b - a + 1) << endl; else if (which == "replace") { cin >> p; str = str.replace(a, b - a + 1, p); } else if (which == "reverse") { string tmp = str.substr(a, b - a + 1); int n = tmp.size(); for (int i = 0; i < n; i++) { str[a + i] = tmp[n - i - 1]; } } } return 0; }
replace
16
20
16
19
0
p02422
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string str; int n; cin >> str >> n; string com; for (int i = 0; i < n; i++) { cin >> com; if (com == "replace") { string str1; int a, b; cin >> a >> b; cin >> str1; str.replace(a, b, str1); } else if (com == "reverse") { int a, b; cin >> a >> b; reverse(&str[a], &str[b] + 1); } else if (com == "print") { int a, b; cin >> a >> b; b = b - a + 1; cout << str.substr(a, b) << endl; } // cout<<str<<endl; } return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string str; int n; cin >> str >> n; string com; for (int i = 0; i < n; i++) { cin >> com; if (com == "replace") { string str1; int a, b; cin >> a >> b; cin >> str1; str.replace(a, b - a + 1, str1); // if(b!=str.size())str+=str.substr(b+1); } else if (com == "reverse") { int a, b; cin >> a >> b; reverse(&str[a], &str[b] + 1); } else if (com == "print") { int a, b; cin >> a >> b; b = b - a + 1; cout << str.substr(a, b) << endl; } // cout<<str<<endl; } return 0; }
replace
18
19
18
20
0
p02422
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string str; int i; int a, b; string order, str1; cin >> str >> i; for (int j = 0; j < i; j++) { cin >> order >> a >> b; if (order == "replace") { cin >> str1; str.replace(a, b, str1); } else if (order == "reverse") { while (b - a > 0) { swap(str[a], str[b]); a++; b--; } } else { cout << str.substr(a, b - a + 1) << endl; } // cout << str << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { string str; int i; int a, b; string order, str1; cin >> str >> i; for (int j = 0; j < i; j++) { cin >> order >> a >> b; if (order == "replace") { cin >> str1; for (int k = 0; k < b - a + 1; k++) str[a + k] = str1[k]; } else if (order == "reverse") { while (b - a > 0) { swap(str[a], str[b]); a++; b--; } } else { cout << str.substr(a, b - a + 1) << endl; } // cout << str << endl; } return 0; }
replace
15
16
15
17
0
p02422
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string str; vector<string> strs; int n; cin >> str >> n; for (int i = 0; i < n; i++) { string op; int a, b; cin >> op >> a >> b; if (op == "replace") { string rep; cin >> rep; str = str.replace(a, b, rep); } else if (op == "reverse") { reverse(str.begin() + a, str.begin() + b + 1); } else { strs.push_back(str.substr(a, b - a + 1)); } } for (int i = 0; i < strs.size(); i++) cout << strs[i] << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string str; vector<string> strs; int n; cin >> str >> n; for (int i = 0; i < n; i++) { string op; int a, b; cin >> op >> a >> b; if (op == "replace") { string tmp; cin >> tmp; // str.replace(a, b, tmp); tmp = str.substr(0, a) + tmp + str.substr(b + 1); str = tmp; } else if (op == "reverse") { reverse(str.begin() + a, str.begin() + b + 1); } else { strs.push_back(str.substr(a, b - a + 1)); } } for (int i = 0; i < strs.size(); i++) cout << strs[i] << endl; }
replace
17
20
17
22
0
p02422
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int main() { string s, order, p; char ch; cin >> s; int n, i, a, b; cin >> n; for (i = 0; i < n; i++) { cin >> order; if (order == "replace") { cin >> a >> b >> p; s.replace(a, b, p); } if (order == "reverse") { cin >> a >> b; int left = a; int right = b; while (left < right) { ch = s.at(right); s.at(right) = s.at(left); s.at(left) = ch; right--; left++; } } if (order == "print") { cin >> a >> b; cout << s.substr(a, b - a + 1) << endl; } } }
#include "bits/stdc++.h" using namespace std; int main() { string s, order, p; char ch; cin >> s; int n, i, a, b; cin >> n; for (i = 0; i < n; i++) { cin >> order; if (order == "replace") { cin >> a >> b >> p; s.replace(a, b - a + 1, p); } if (order == "reverse") { cin >> a >> b; int left = a; int right = b; while (left < right) { ch = s.at(right); s.at(right) = s.at(left); s.at(left) = ch; right--; left++; } } if (order == "print") { cin >> a >> b; cout << s.substr(a, b - a + 1) << endl; } } }
replace
12
13
12
13
0
p02422
C++
Runtime Error
#include <iostream> #include <string.h> #include <string> using namespace std; char str[1000 + 1] = {0}; void print(int a, int b) { for (; a <= b; a++) cout << str[a]; cout << endl; } void reverse(int a, int b) { char temp = '\0'; while (a < b) { temp = str[a]; str[a] = str[b]; str[b] = temp; a++; b--; } } void replace(int a, int b, const char *p) { for (int i = 0; i < b - a + 1; i++) str[i + a] = p[i]; } int main() { char command[7 + 1] = {0}, p[100 + 1] = {0}; int q = 0, a = 0, b = 0; cin >> str >> q; for (int i = 0; i < q; i++) { cin >> command >> a >> b; if (command[0] == 'p') { print(a, b); } else if (command[2] == 'v') { reverse(a, b); } else { cin >> p; replace(a, b, p); } } return 0; }
#include <iostream> #include <string.h> #include <string> using namespace std; char str[1000 + 1] = {0}; void print(int a, int b) { for (; a <= b; a++) cout << str[a]; cout << endl; } void reverse(int a, int b) { char temp = '\0'; while (a < b) { temp = str[a]; str[a] = str[b]; str[b] = temp; a++; b--; } } void replace(int a, int b, const char *p) { for (int i = 0; i < b - a + 1; i++) str[i + a] = p[i]; } int main() { char command[7 + 1] = {0}, p[1000 + 1] = {0}; int q = 0, a = 0, b = 0; cin >> str >> q; for (int i = 0; i < q; i++) { cin >> command >> a >> b; if (command[0] == 'p') { print(a, b); } else if (command[2] == 'v') { reverse(a, b); } else { cin >> p; replace(a, b, p); } } return 0; }
replace
29
30
29
30
0
p02431
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 1e9 template <class T> class treap { public: struct node { T val, sum, mini, maxi; node *left, *right; int pri; unsigned sz; node(T val, int pri) : val(val), sum(val), mini(val), maxi(val), pri(pri), sz(1) { left = right = NULL; } }; node *root; treap() : root(NULL) { srand(time(NULL)); } unsigned size() { return size(root); } unsigned size(node *v) { return !v ? 0 : v->sz; } T sum(node *v) { return !v ? 0 : v->sum; } T MIN(node *v) { return !v ? INF : v->mini; } T MAX(node *v) { return !v ? -INF : v->maxi; } node *update(node *v) { v->sz = size(v->left) + size(v->right) + 1; v->sum = sum(v->left) + sum(v->right) + v->val; v->mini = min(MIN(v->left), MIN(v->right)); v->maxi = max(MAX(v->left), MAX(v->right)); return v; } node *merge(node *s, node *t) { if (!s || !t) return s ? s : t; if (s->pri > t->pri) { s->right = merge(s->right, t); return update(s); } else { t->left = merge(s, t->left); return update(t); } } pair<node *, node *> split(node *v, unsigned k) { if (!v) return pair<node *, node *>(NULL, NULL); if (k <= size(v->left)) { pair<node *, node *> s = split(v->left, k); v->left = s.second; return make_pair(s.first, update(v)); } else { pair<node *, node *> s = split(v->right, k - size(v->left) - 1); v->right = s.first; return make_pair(update(v), s.second); } } node *find(unsigned k) { node *v = root; while (v) { unsigned s = size(v->left); if (s > k) v = v->left; else if (s == k) break; else { v = v->right; k -= s + 1; } } return v; } int getval(int k) { node *t = find(k); return t->val; } void insert(unsigned k, T val) { root = insert(root, k, val, rand()); } node *insert(node *t, unsigned k, T val, int pri) { pair<node *, node *> s = split(t, k); t = merge(s.first, new node(val, pri)); t = merge(t, s.second); return update(t); } void erase(int k) { root = erase(root, k); } node *erase(node *t, unsigned k) { pair<node *, node *> u, v; u = split(t, k + 1); v = split(u.first, k); t = merge(v.first, u.second); return update(t); } void range_erase(int l, int r) { root = range_erase(root, l, r); } node range_erase(node *t, unsigned k) { pair<node *, node *> u, v; } void push_back(T val) { insert(root ? root->sz : 0, val); } void pop_back() { erase(root->sz - 1); } void print_array() { int k = root->sz; cout << "root value = " << root->val << endl; cout << "size of array = " << k << endl; for (int i = 0; i < k; i++) { if (i) cout << " "; cout << getval(i); } cout << endl; } }; int main() { treap<int> tri; int q; cin >> q; while (q--) { int a, b; cin >> a; if (a != 2) cin >> b; if (a == 0) tri.push_back(b); if (a == 2) tri.pop_back(); if (a == 1) cout << tri.getval(b) << endl; } /*while(1){ int a,b,c; cin>>a>>b; if(a!=-1)tri.insert(b,a); else tri.erase(b); tri.print_array(); }*/ }
#include <bits/stdc++.h> using namespace std; #define INF 1e9 template <class T> class treap { public: struct node { T val, sum, mini, maxi; node *left, *right; int pri; unsigned sz; node(T val, int pri) : val(val), sum(val), mini(val), maxi(val), pri(pri), sz(1) { left = right = NULL; } }; node *root; treap() : root(NULL) { srand(time(NULL)); } unsigned size() { return size(root); } unsigned size(node *v) { return !v ? 0 : v->sz; } T sum(node *v) { return !v ? 0 : v->sum; } T MIN(node *v) { return !v ? INF : v->mini; } T MAX(node *v) { return !v ? -INF : v->maxi; } node *update(node *v) { v->sz = size(v->left) + size(v->right) + 1; v->sum = sum(v->left) + sum(v->right) + v->val; v->mini = min(MIN(v->left), MIN(v->right)); v->maxi = max(MAX(v->left), MAX(v->right)); return v; } node *merge(node *s, node *t) { if (!s || !t) return s ? s : t; if (s->pri > t->pri) { s->right = merge(s->right, t); return update(s); } else { t->left = merge(s, t->left); return update(t); } } pair<node *, node *> split(node *v, unsigned k) { if (!v) return pair<node *, node *>(NULL, NULL); if (k <= size(v->left)) { pair<node *, node *> s = split(v->left, k); v->left = s.second; return make_pair(s.first, update(v)); } else { pair<node *, node *> s = split(v->right, k - size(v->left) - 1); v->right = s.first; return make_pair(update(v), s.second); } } node *find(unsigned k) { node *v = root; while (v) { unsigned s = size(v->left); if (s > k) v = v->left; else if (s == k) break; else { v = v->right; k -= s + 1; } } return v; } int getval(int k) { node *t = find(k); return t->val; } void insert(unsigned k, T val) { root = insert(root, k, val, rand()); } node *insert(node *t, unsigned k, T val, int pri) { pair<node *, node *> s = split(t, k); t = merge(s.first, new node(val, pri)); t = merge(t, s.second); return update(t); } void erase(int k) { root = erase(root, k); } node *erase(node *t, unsigned k) { if (root->sz == 1) { root = NULL; return NULL; } pair<node *, node *> u, v; u = split(t, k + 1); v = split(u.first, k); t = merge(v.first, u.second); return update(t); } void range_erase(int l, int r) { root = range_erase(root, l, r); } node range_erase(node *t, unsigned k) { pair<node *, node *> u, v; } void push_back(T val) { insert(root ? root->sz : 0, val); } void pop_back() { erase(root->sz - 1); } void print_array() { int k = root->sz; cout << "root value = " << root->val << endl; cout << "size of array = " << k << endl; for (int i = 0; i < k; i++) { if (i) cout << " "; cout << getval(i); } cout << endl; } }; int main() { treap<int> tri; int q; cin >> q; while (q--) { int a, b; cin >> a; if (a != 2) cin >> b; if (a == 0) tri.push_back(b); if (a == 2) tri.pop_back(); if (a == 1) cout << tri.getval(b) << endl; } /*while(1){ int a,b,c; cin>>a>>b; if(a!=-1)tri.insert(b,a); else tri.erase(b); tri.print_array(); }*/ }
insert
96
96
96
100
0
p02433
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { list<int> a; list<int>::iterator it = a.end(); int q, query, t, x; cin >> q; for (int i = 0; i < q; i++) { cin >> query; if (query == 0) { cin >> x; it = a.insert(it, x); } else if (query == 1) { cin >> x; if (x > 0) for (int i = 0; i < x; i++) it++; else { x *= -1; for (int i = 0; i < x; i++) it--; } } else { a.erase(it); } // cout<<" "<<i<<endl; } for (it = a.begin(); it != a.end(); it++) { cout << *it << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { list<int> a; list<int>::iterator it = a.end(); int q, query, t, x; cin >> q; for (int i = 0; i < q; i++) { cin >> query; if (query == 0) { cin >> x; it = a.insert(it, x); } else if (query == 1) { cin >> x; if (x > 0) for (int i = 0; i < x; i++) it++; else { x *= -1; for (int i = 0; i < x; i++) it--; } } else { it = a.erase(it); } // cout<<" "<<i<<endl; } for (it = a.begin(); it != a.end(); it++) { cout << *it << endl; } return 0; }
replace
26
27
26
27
0
p02435
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; vector<stack<int>> vs(n); for (int i = 0; i < q; i++) { int a; cin >> a; if (a == 0) { int t, x; cin >> t >> x; vs.at(t).push(x); } if (a == 1) { int t; cin >> t; cout << vs.at(t).top() << endl; } if (a == 2) { int t; cin >> t; if (!vs.at(t).empty()) vs.at(t).pop(); } } }
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; vector<stack<int>> vs(n); for (int i = 0; i < q; i++) { int a; cin >> a; if (a == 0) { int t, x; cin >> t >> x; vs.at(t).push(x); } if (a == 1) { int t; cin >> t; if (!vs.at(t).empty()) cout << vs.at(t).top() << endl; } if (a == 2) { int t; cin >> t; if (!vs.at(t).empty()) vs.at(t).pop(); } } }
replace
18
19
18
20
0
p02435
C++
Runtime Error
#include <iostream> #include <stack> using namespace std; int main() { int n, q; cin >> n >> q; stack<int> a[n]; for (int i = 0; i < q; i++) { int n, t; cin >> n >> t; if (!n) { int x; cin >> x; a[t].push(x); } else if (n == 1 && !a[t].empty()) cout << a[t].top() << endl; else a[t].pop(); } return 0; }
#include <iostream> #include <stack> using namespace std; int main() { int n, q; cin >> n >> q; stack<int> a[n]; for (int i = 0; i < q; i++) { int n, t; cin >> n >> t; if (!n) { int x; cin >> x; a[t].push(x); } else if (n == 1 && !a[t].empty()) cout << a[t].top() << endl; else if (!a[t].empty()) a[t].pop(); } return 0; }
replace
18
19
18
19
0
p02435
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; vector<stack<int>> s(n); while (q--) { int y; cin >> y; if (y == 0) { int t, x; cin >> t >> x; s[t].push(x); } else if (y == 1) { int t; cin >> t; if (!s[t].empty()) { cout << s[t].top() << endl; } } else { int t; cin >> t; s[t].pop(); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; vector<stack<int>> s(n); while (q--) { int y; cin >> y; if (y == 0) { int t, x; cin >> t >> x; s[t].push(x); } else if (y == 1) { int t; cin >> t; if (!s[t].empty()) { cout << s[t].top() << endl; } } else { int t; cin >> t; if (!s[t].empty()) { s[t].pop(); } } } return 0; }
replace
23
24
23
26
0
p02435
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<stack<int>> st; void f0() { int p1, p2; cin >> p1 >> p2; st[p1].push(p2); } void f1() { int p; cin >> p; cout << st[p].top() << endl; } void f2() { int p; cin >> p; if (!st[p].empty()) st[p].pop(); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; st.resize(n); while (q--) { int op; cin >> op; switch (op) { case 0: f0(); break; case 1: f1(); break; case 2: f2(); break; } } return 0; }
#include <bits/stdc++.h> using namespace std; vector<stack<int>> st; void f0() { int p1, p2; cin >> p1 >> p2; st[p1].push(p2); } void f1() { int p; cin >> p; if (!st[p].empty()) cout << st[p].top() << endl; } void f2() { int p; cin >> p; if (!st[p].empty()) st[p].pop(); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; st.resize(n); while (q--) { int op; cin >> op; switch (op) { case 0: f0(); break; case 1: f1(); break; case 2: f2(); break; } } return 0; }
replace
17
18
17
19
0
p02435
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using lint = long long; template <typename T = lint> inline T in() { T x; cin >> x; return x; } #define INF 1e9 #define INFL static_cast<lint>(INF) #define REP(i, n) for (lint i = 0, i##_len = (n); i < i##_len; ++i) #define REP1(i, n) for (lint i = 1, i##_len = (n); i <= i##_len; ++i) #define REPI(i, ini, n) for (lint i = (ini), i##_len = (n); i < i##_len; ++i) #define REPC(i, obj) for (auto i : obj) #define R_UP(a, b) (((a) + (b)-1) / (b)) #define ALL(obj) (obj).begin(), (obj).end() int main() { int n = in(), q = in(); vector<stack<int>> s(n); REP(i, q) { int t, x; switch (in()) { case 0: t = in(), x = in(); s[t].push(x); break; case 1: t = in(); if (s[t].size() != 0) cout << s[t].top() << endl; break; case 2: t = in(); s[t].pop(); break; } } }
#include <bits/stdc++.h> using namespace std; using lint = long long; template <typename T = lint> inline T in() { T x; cin >> x; return x; } #define INF 1e9 #define INFL static_cast<lint>(INF) #define REP(i, n) for (lint i = 0, i##_len = (n); i < i##_len; ++i) #define REP1(i, n) for (lint i = 1, i##_len = (n); i <= i##_len; ++i) #define REPI(i, ini, n) for (lint i = (ini), i##_len = (n); i < i##_len; ++i) #define REPC(i, obj) for (auto i : obj) #define R_UP(a, b) (((a) + (b)-1) / (b)) #define ALL(obj) (obj).begin(), (obj).end() int main() { int n = in(), q = in(); vector<stack<int>> s(n); REP(i, q) { int t, x; switch (in()) { case 0: t = in(), x = in(); s[t].push(x); break; case 1: t = in(); if (s[t].size() != 0) cout << s[t].top() << endl; break; case 2: t = in(); if (s[t].size() != 0) s[t].pop(); break; } } }
replace
33
34
33
35
0
p02435
C++
Runtime Error
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n, q; cin >> n >> q; stack<int> s[n]; while (q--) { int a, b, c; cin >> a >> b; if (!a) { cin >> c; s[b].push(c); } else if (a == 1) { cout << s[b].top() << endl; } else if (!s[b].empty()) s[b].pop(); } }
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n, q; cin >> n >> q; stack<int> s[n]; while (q--) { int a, b, c; cin >> a >> b; if (!a) { cin >> c; s[b].push(c); } else if (a == 1) { if (!s[b].empty()) cout << s[b].top() << endl; } else if (!s[b].empty()) s[b].pop(); } }
replace
15
16
15
17
0
p02435
Python
Runtime Error
from collections import deque if __name__ == "__main__": n, q = input().split() n, q = int(n), int(q) S = [deque([]) for i in range(n)] for i in range(q): query = input().split() if query[0] == "0": S[int(query[1])].append(query[2]) else: if len(S) == 0: pass elif query[0] == "1": print(S[int(query[1])][-1]) else: S[int(query[1])].pop()
from collections import deque if __name__ == "__main__": n, q = input().split() n, q = int(n), int(q) S = [deque([]) for i in range(n)] for i in range(q): query = input().split() if query[0] == "0": S[int(query[1])].append(query[2]) else: if len(S[int(query[1])]) == 0: pass elif query[0] == "1": print(S[int(query[1])][-1]) else: S[int(query[1])].pop()
replace
14
15
14
15
0
p02435
Python
Runtime Error
n, q = list(map(int, input().split(" "))) stacks = [[] for i in range(n)] for i in range(q): op = list(map(int, input().split(" "))) if op[0] == 0: stacks[op[1]].append(op[2]) elif op[0] == 1: if len(stacks[op[1]]) != 0: print(stacks[op[1]][-1]) elif op[0] == 2: stacks[op[1]].pop()
n, q = list(map(int, input().split(" "))) stacks = [[] for i in range(n)] for i in range(q): op = list(map(int, input().split(" "))) if op[0] == 0: stacks[op[1]].append(op[2]) elif op[0] == 1: if len(stacks[op[1]]) != 0: print(stacks[op[1]][-1]) elif op[0] == 2: if len(stacks[op[1]]) != 0: stacks[op[1]].pop()
replace
11
12
11
13
0
p02435
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stack> #include <string> #include <vector> using namespace std; int main() { int n, q; cin >> n >> q; vector<stack<int>> s(n); for (int i = 0; i < q; i++) { int a, t, x; cin >> a; if (a == 0) { cin >> t >> x; s[t].push(x); } if (a == 1) { cin >> t; if (!s[t].empty()) { cout << s[t].top() << endl; } } if (a == 2) { cin >> t; s[t].pop(); } } return 0; }
#include <algorithm> #include <iostream> #include <stack> #include <string> #include <vector> using namespace std; int main() { int n, q; cin >> n >> q; vector<stack<int>> s(n); for (int i = 0; i < q; i++) { int a, t, x; cin >> a; if (a == 0) { cin >> t >> x; s[t].push(x); } if (a == 1) { cin >> t; if (!s[t].empty()) { cout << s[t].top() << endl; } } if (a == 2) { cin >> t; if (!s[t].empty()) { s[t].pop(); } } } return 0; }
replace
33
34
33
36
0
p02437
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #define long long long #define LF '\n' using namespace std; typedef pair<int, int> pii; template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a ? a = b, 1 : 0; } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a ? a = b, 1 : 0; } constexpr int INF = 0x3f3f3f3f; priority_queue<int> pq[1005]; signed main() { cin.tie(nullptr), ios::sync_with_stdio(false); int n, q; cin >> n >> q; while (q--) { int com, t, x; cin >> com; if (com == 0) { cin >> t >> x; pq[t].emplace(x); } else if (com == 1) { cin >> t; cout << pq[t].top() << LF; } else { cin >> t; if (pq[t].size()) pq[t].pop(); } } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #define long long long #define LF '\n' using namespace std; typedef pair<int, int> pii; template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a ? a = b, 1 : 0; } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a ? a = b, 1 : 0; } constexpr int INF = 0x3f3f3f3f; priority_queue<int> pq[1005]; signed main() { cin.tie(nullptr), ios::sync_with_stdio(false); int n, q; cin >> n >> q; while (q--) { int com, t, x; cin >> com; if (com == 0) { cin >> t >> x; pq[t].emplace(x); } else if (com == 1) { cin >> t; if (pq[t].size()) cout << pq[t].top() << LF; } else { cin >> t; if (pq[t].size()) pq[t].pop(); } } return 0; }
replace
34
35
34
36
0
p02440
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <set> using namespace std; int main() { int n, q; set<int> a; cin >> n; for (int i = 0, t; i < n && cin >> t; i++) a.insert(t); cin >> q; for (int i = 0, k; i < q; i++) { cin >> k; cout << binary_search(a.begin(), a.end(), k) << endl; } return 0; }
#include <algorithm> #include <iostream> #include <set> using namespace std; int main() { int n, q; set<int> a; cin >> n; for (int i = 0, t; i < n && cin >> t; i++) a.insert(t); cin >> q; for (int i = 0, k; i < q; i++) { cin >> k; cout << (a.find(k) != a.end()) << endl; } return 0; }
replace
14
15
14
15
TLE
p02441
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, q; cin >> n; vector<int> a; for (int i = 0; i < n; i++) cin >> a[i]; cin >> q; for (int i = 0, k; i < q; i++) { cin >> k; cout << distance(a.begin(), lower_bound(a.begin(), a.end(), k)) << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, q; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; cin >> q; for (int i = 0, k; i < q; i++) { cin >> k; cout << distance(a.begin(), lower_bound(a.begin(), a.end(), k)) << endl; } return 0; }
replace
7
8
7
8
-11
p02449
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int n; vector<vector<int>> v; vector<int> a, c; int kaijo(int x) { int ans = 1; for (int i = 1; i <= x; i++) ans *= i; return ans; } int main() { cin >> n; a.resize(n); c.resize(n); rep(i, n) cin >> a[i]; rep(i, n) c[i] = i + 1; do { v.push_back(c); } while (next_permutation(c.begin(), c.end())); rep(i, v.size()) { if (v[i] == a) { if (i == 0) { rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); return 0; } else if (i == v.size() - 1) { i--; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); return 0; } else { i--; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); return 0; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int n; vector<vector<int>> v; vector<int> a, c; int kaijo(int x) { int ans = 1; for (int i = 1; i <= x; i++) ans *= i; return ans; } int main() { cin >> n; a.resize(n); c.resize(n); rep(i, n) cin >> a[i]; if (n == 1) { puts("1"); return 0; } rep(i, n) c[i] = i + 1; do { v.push_back(c); } while (next_permutation(c.begin(), c.end())); rep(i, v.size()) { if (v[i] == a) { if (i == 0) { rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); return 0; } else if (i == v.size() - 1) { i--; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); return 0; } else { i--; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); i++; rep(j, v[i].size()) cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " "); return 0; } } } return 0; }
insert
17
17
17
21
0
p02452
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; static const int MAX_N = 100000; int n, a[MAX_N], m, b[MAX_N]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; for (int i = 0; i < m; i++) cin >> b[i]; bool flag = true; for (int i = 0; i < m; i++) { if ((upper_bound(a, a + n, b[i])) - a == lower_bound(a, a + n, b[i]) - a) flag = false; } if (flag) cout << 1 << endl; else cout << 0 << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX_N = 200000; int n, a[MAX_N], m, b[MAX_N]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; for (int i = 0; i < m; i++) cin >> b[i]; bool flag = true; for (int i = 0; i < m; i++) { if ((upper_bound(a, a + n, b[i])) - a == lower_bound(a, a + n, b[i]) - a) flag = false; } if (flag) cout << 1 << endl; else cout << 0 << endl; return 0; }
replace
3
4
3
4
0
p02452
C++
Runtime Error
#include <iostream> using namespace std; long long a[200000]; int main() { int n, m, j = 0; bool f = 1; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; for (int i = 0; i < m; i++) { long long b; cin >> b; while (b > a[j]) j++; if (b < a[j]) { f = 0; break; } } cout << f << endl; return 0; }
#include <iostream> using namespace std; long long a[200000]; int main() { int n, m, j = 0; bool f = 1; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; a[n] = 1000000001; cin >> m; for (int i = 0; i < m; i++) { long long b; cin >> b; while (b > a[j]) j++; if (b < a[j]) { f = 0; break; } } cout << f << endl; return 0; }
insert
13
13
13
14
0
p02456
C++
Runtime Error
#include <algorithm> #include <cassert> #include <chrono> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 1000000007; template <typename T, typename U> class treap { private: struct node { ll priority; T key; U a; node *parent; node *right; node *left; }; random_device r; mt19937 mt; list<node> tree; node *root; node leaf = {0, T(), U(), NULL, NULL, NULL}; ll Size; node *search(T key) { if (Size == 0) { return err(); } node *where = root; while (1) { if ((*where).key == key) { return where; } if ((*where).right != err() && (*where).key < key) { where = (*where).right; continue; } if ((*where).left != err() && key < (*where).key) { where = (*where).left; continue; } return where; } return err(); } node *err() { return &leaf; } ll mk_pr() { uniform_int_distribution<int> R(1, 1000000000); return R(mt); } void parent_change(node &P, node *from, node *to) { if (P.right == from) { P.right = to; return; } else if (P.left == from) { P.left = to; return; } assert(false); } void parent_change(node *P, node *from, node *to) { parent_change(*P, from, to); } node *rotateL(node &where) { node *right = where.right; assert(right != err()); node *L = (*right).left; if (L != err()) { where.right = L; (*L).parent = &where; } else { where.right = err(); } (*right).left = &where; if (where.parent == err()) { root = right; (*right).parent = err(); } else { (*right).parent = where.parent; parent_change((*right).parent, &where, right); } where.parent = right; return right; } node *rotateR(node &where) { node *left = where.left; assert(left != err()); node *R = (*left).right; if (R != err()) { where.left = R; (*R).parent = &where; } else { where.left = err(); } (*left).right = &where; if (where.parent == err()) { root = left; (*left).parent = err(); } else { (*left).parent = where.parent; parent_change((*left).parent, &where, left); } where.parent = left; return left; } node *rotate(node &where) { node *P = where.parent; if (P != err() && (*P).priority < where.priority) { if ((*P).right == &where) { rotateL(*P); } else { rotateR(*P); } } return &where; } node *rotate(node *where) { return rotate(*where); } node *Max(node *where) { assert(where != err()); while (1) { if ((*where).right == err()) { return where; } where = (*where).right; } return err(); } node *Min(node *where) { assert(where != err()); while (1) { if ((*where).left == err()) { return where; } where = (*where).left; } return err(); } node *erase(node *where) { if ((*where).right != err() && (*where).left != err()) { node *ers = Min((*where).right); (*where).key = (*ers).key; (*where).a = (*ers).a; erase(ers); return where; } node *ret; if ((*where).right == err() && (*where).left == err()) { if (where == root) { root = err(); return err(); } parent_change((*where).parent, where, err()); ret = (*where).parent; } else if ((*where).right != err()) { if (where == root) { root = (*where).right; (*(*where).right).parent = err(); return root; } parent_change((*where).parent, where, (*where).right); (*(*where).right).parent = (*where).parent; ret = (*where).parent; } else { if (where == root) { root = (*where).left; (*(*where).left).parent = err(); return root; } parent_change((*where).parent, where, (*where).left); (*(*where).left).parent = (*where).parent; ret = (*where).parent; } return ret; } public: treap() : mt(r()) { Size = 0; root = err(); } void insert(T key, U a) { if (Size == 0) { tree.push_front({mk_pr(), key, a, err(), err(), err()}); Size++; root = &(*tree.begin()); return; } node *where = search(key); if ((*where).key == key) { (*where).a = a; } else { tree.push_front({mk_pr(), key, a, where, err(), err()}); node *New = &(*tree.begin()); if ((*where).key < key) { (*where).right = New; } else { (*where).left = New; } while (New != err()) { New = rotate(New); New = (*New).parent; } Size++; } } U *find(T key) { if (Size == 0) { return end(); } node *where = search(key); if ((*where).key == key) { return &(*where).a; } return end(); } U *end() { return &leaf.a; } ll size() { return Size; } U *erase(T key) { node *where = search(key); if ((*where).key != key) { return end(); } Size--; return &(*erase(where)).a; } void print() { if (Size == 0) { return; } dfs(root); } void dfs(node *where) { assert(where != err()); cout << (*where).key << " " << (*where).priority << endl; if ((*where).right != err()) { dfs((*where).right); } if ((*where).left != err()) { dfs((*where).left); } } void test() { mid_dfs(root); cout << endl; first_dfs(root); cout << endl; } void mid_dfs(node *where) { assert(where != err()); if ((*where).left != err()) { mid_dfs((*where).left); } cout << " " << (*where).a; if ((*where).right != err()) { mid_dfs((*where).right); } } void first_dfs(node *where) { assert(where != err()); cout << " " << (*where).a; if ((*where).left != err()) { first_dfs((*where).left); } if ((*where).right != err()) { first_dfs((*where).right); } } }; int main() { treap<ll, ll> T; ll q; cin >> q; while (q--) { ll com; cin >> com; if (com == 0) { ll x; cin >> x; T.insert(x, x); cout << T.size() << endl; } else if (com == 1) { ll x; cin >> x; if (T.find(x) == T.end()) { cout << 0 << endl; } else { cout << 1 << endl; } } else { ll x; cin >> x; T.erase(x); } } return 0; }
#include <algorithm> #include <cassert> #include <chrono> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 1000000007; template <typename T, typename U> class treap { private: struct node { ll priority; T key; U a; node *parent; node *right; node *left; }; random_device r; mt19937 mt; list<node> tree; node *root; node leaf = {0, T(), U(), NULL, NULL, NULL}; ll Size; node *search(T key) { if (Size == 0) { return err(); } node *where = root; while (1) { if ((*where).key == key) { return where; } if ((*where).right != err() && (*where).key < key) { where = (*where).right; continue; } if ((*where).left != err() && key < (*where).key) { where = (*where).left; continue; } return where; } return err(); } node *err() { return &leaf; } ll mk_pr() { uniform_int_distribution<int> R(1, 1000000000); return R(mt); } void parent_change(node &P, node *from, node *to) { if (P.right == from) { P.right = to; return; } else if (P.left == from) { P.left = to; return; } assert(false); } void parent_change(node *P, node *from, node *to) { parent_change(*P, from, to); } node *rotateL(node &where) { node *right = where.right; assert(right != err()); node *L = (*right).left; if (L != err()) { where.right = L; (*L).parent = &where; } else { where.right = err(); } (*right).left = &where; if (where.parent == err()) { root = right; (*right).parent = err(); } else { (*right).parent = where.parent; parent_change((*right).parent, &where, right); } where.parent = right; return right; } node *rotateR(node &where) { node *left = where.left; assert(left != err()); node *R = (*left).right; if (R != err()) { where.left = R; (*R).parent = &where; } else { where.left = err(); } (*left).right = &where; if (where.parent == err()) { root = left; (*left).parent = err(); } else { (*left).parent = where.parent; parent_change((*left).parent, &where, left); } where.parent = left; return left; } node *rotate(node &where) { node *P = where.parent; if (P != err() && (*P).priority < where.priority) { if ((*P).right == &where) { rotateL(*P); } else { rotateR(*P); } } return &where; } node *rotate(node *where) { return rotate(*where); } node *Max(node *where) { assert(where != err()); while (1) { if ((*where).right == err()) { return where; } where = (*where).right; } return err(); } node *Min(node *where) { assert(where != err()); while (1) { if ((*where).left == err()) { return where; } where = (*where).left; } return err(); } node *erase(node *where) { if ((*where).right != err() && (*where).left != err()) { node *ers = Min((*where).right); (*where).key = (*ers).key; (*where).a = (*ers).a; erase(ers); return where; } node *ret; if ((*where).right == err() && (*where).left == err()) { if (where == root) { root = err(); return err(); } parent_change((*where).parent, where, err()); ret = (*where).parent; } else if ((*where).right != err()) { if (where == root) { root = (*where).right; (*(*where).right).parent = err(); return root; } parent_change((*where).parent, where, (*where).right); (*(*where).right).parent = (*where).parent; ret = (*where).parent; } else { if (where == root) { root = (*where).left; (*(*where).left).parent = err(); return root; } parent_change((*where).parent, where, (*where).left); (*(*where).left).parent = (*where).parent; ret = (*where).parent; } return ret; } public: treap() : mt(r()) { Size = 0; root = err(); } void insert(T key, U a) { if (Size == 0) { tree.push_front({mk_pr(), key, a, err(), err(), err()}); Size++; root = &(*tree.begin()); return; } node *where = search(key); if ((*where).key == key) { (*where).a = a; } else { tree.push_front({mk_pr(), key, a, where, err(), err()}); node *New = &(*tree.begin()); if ((*where).key < key) { (*where).right = New; } else { (*where).left = New; } while (New != err()) { New = rotate(New); New = (*New).parent; } Size++; } } U *find(T key) { if (Size == 0) { return end(); } node *where = search(key); if ((*where).key == key) { return &(*where).a; } return end(); } U *end() { return &leaf.a; } ll size() { return Size; } U *erase(T key) { node *where = search(key); if (where == err()) { return end(); } if ((*where).key != key) { return end(); } Size--; return &(*erase(where)).a; } void print() { if (Size == 0) { return; } dfs(root); } void dfs(node *where) { assert(where != err()); cout << (*where).key << " " << (*where).priority << endl; if ((*where).right != err()) { dfs((*where).right); } if ((*where).left != err()) { dfs((*where).left); } } void test() { mid_dfs(root); cout << endl; first_dfs(root); cout << endl; } void mid_dfs(node *where) { assert(where != err()); if ((*where).left != err()) { mid_dfs((*where).left); } cout << " " << (*where).a; if ((*where).right != err()) { mid_dfs((*where).right); } } void first_dfs(node *where) { assert(where != err()); cout << " " << (*where).a; if ((*where).left != err()) { first_dfs((*where).left); } if ((*where).right != err()) { first_dfs((*where).right); } } }; int main() { treap<ll, ll> T; ll q; cin >> q; while (q--) { ll com; cin >> com; if (com == 0) { ll x; cin >> x; T.insert(x, x); cout << T.size() << endl; } else if (com == 1) { ll x; cin >> x; if (T.find(x) == T.end()) { cout << 0 << endl; } else { cout << 1 << endl; } } else { ll x; cin >> x; T.erase(x); } } return 0; }
insert
261
261
261
264
0
p02456
C++
Runtime Error
#include <algorithm> #include <cassert> #include <chrono> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 1000000007; template <typename T> class List { private: typedef unsigned long ul; struct node { node *front; node *back; T a; }; ul Size; node *root; node *create(T a) { node *New = (node *)malloc(sizeof(node)); assert(New != NULL); (*New).a = a; return New; } public: struct iterator { node *where; iterator(node *where) : where(where) {} iterator(T *t) { char *C = (char *)t; C -= 2 * sizeof(node *); where = (node *)C; } iterator &operator++() { where = (*where).back; return *this; } iterator &operator--() { where = (*where).front; return *this; } iterator operator++(int) { iterator ret = *this; where = (*where).back; return ret; } iterator operator--(int) { iterator ret = *this; where = (*where).front; return ret; } bool operator==(const iterator &I) const { return where == I.where; } bool operator!=(const iterator &I) const { return where != I.where; } T &operator*() { return (*where).a; } T *pointer() { return &(*where).a; } }; List() { Size = 0; root = create(T()); (*root).back = root; (*root).front = root; } iterator begin() { return iterator((*root).back); } iterator end() { return iterator(root); } ul size() { return Size; } iterator push_back(T a) { node *New = create(a); node *F = (*root).front; (*F).back = New; (*New).front = F; (*root).front = New; (*New).back = root; Size++; return iterator(New); } iterator push_front(T a) { node *New = create(a); node *B = (*root).back; (*root).back = New; (*New).front = root; (*B).front = New; (*New).back = B; Size++; return (New); } iterator pop_back() { if (Size == 0) { return root; } node *E = (*root).front; node *F = (*E).front; (*F).back = root; (*root).front = F; free(E); Size--; return iterator(root); } iterator pop_front() { if (Size == 0) { return root; } node *E = (*root).back; node *B = (*E).back; (*B).front = root; (*root).back = B; free(E); Size--; return iterator(B); } iterator erase(iterator where) { node *E = where.where; if (Size == 0 || E == root) { return iterator(root); } node *F = (*E).front; node *B = (*E).back; (*F).back = B; (*B).front = F; free(E); Size--; return B; } iterator erase(T *where) { return erase(iterator(where)); } iterator erase(node *E) { if (Size == 0 || E == root) { return iterator(root); } node *F = (*E).front; node *B = (*E).back; (*F).back = B; (*B).front = F; free(E); Size--; return B; } }; template <typename T, typename U> class treap { private: struct node { ll priority; T key; U a; node *parent; node *right; node *left; }; random_device r; mt19937 mt; List<node> tree; node *root; node leaf = {0, T(), U(), NULL, NULL, NULL}; ll Size; node *search(T key) { if (Size == 0) { return err(); } node *where = root; while (1) { if ((*where).key == key) { return where; } if ((*where).right != err() && (*where).key < key) { where = (*where).right; continue; } if ((*where).left != err() && key < (*where).key) { where = (*where).left; continue; } return where; } return err(); } node *err() { return &leaf; } ll mk_pr() { uniform_int_distribution<int> R(1, 1000000000); return R(mt); } void parent_change(node &P, node *from, node *to) { if (P.right == from) { P.right = to; return; } else if (P.left == from) { P.left = to; return; } assert(false); } void parent_change(node *P, node *from, node *to) { parent_change(*P, from, to); } node *rotateL(node &where) { node *right = where.right; assert(right != err()); node *L = (*right).left; if (L != err()) { where.right = L; (*L).parent = &where; } else { where.right = err(); } (*right).left = &where; if (where.parent == err()) { root = right; (*right).parent = err(); } else { (*right).parent = where.parent; parent_change((*right).parent, &where, right); } where.parent = right; return right; } node *rotateR(node &where) { node *left = where.left; assert(left != err()); node *R = (*left).right; if (R != err()) { where.left = R; (*R).parent = &where; } else { where.left = err(); } (*left).right = &where; if (where.parent == err()) { root = left; (*left).parent = err(); } else { (*left).parent = where.parent; parent_change((*left).parent, &where, left); } where.parent = left; return left; } node *rotate(node &where) { node *P = where.parent; if (P != err() && (*P).priority < where.priority) { if ((*P).right == &where) { rotateL(*P); } else { rotateR(*P); } } return &where; } node *rotate(node *where) { return rotate(*where); } node *Max(node *where) { assert(where != err()); while (1) { if ((*where).right == err()) { return where; } where = (*where).right; } return err(); } node *Min(node *where) { assert(where != err()); while (1) { if ((*where).left == err()) { return where; } where = (*where).left; } return err(); } node *erase(node *where) { if ((*where).right != err() && (*where).left != err()) { node *ers = Min((*where).right); (*where).key = (*ers).key; (*where).a = (*ers).a; erase(ers); return where; } node *ret; if ((*where).right == err() && (*where).left == err()) { if (where == root) { root = err(); return err(); } parent_change((*where).parent, where, err()); ret = (*where).parent; tree.erase(where); } else if ((*where).right != err()) { if (where == root) { root = (*where).right; (*(*where).right).parent = err(); tree.erase(where); return root; } parent_change((*where).parent, where, (*where).right); (*(*where).right).parent = (*where).parent; ret = (*where).parent; tree.erase(where); } else { if (where == root) { root = (*where).left; (*(*where).left).parent = err(); tree.erase(where); return root; } parent_change((*where).parent, where, (*where).left); (*(*where).left).parent = (*where).parent; ret = (*where).parent; tree.erase(where); } return ret; } public: treap() : mt(r()) { Size = 0; root = err(); } void insert(T key, U a) { if (Size == 0) { tree.push_front({mk_pr(), key, a, err(), err(), err()}); Size++; root = &(*tree.begin()); return; } node *where = search(key); if ((*where).key == key) { (*where).a = a; } else { tree.push_front({mk_pr(), key, a, where, err(), err()}); node *New = &(*tree.begin()); if ((*where).key < key) { (*where).right = New; } else { (*where).left = New; } while (New != err()) { New = rotate(New); New = (*New).parent; } Size++; } } U *find(T key) { if (Size == 0) { return end(); } node *where = search(key); if ((*where).key == key) { return &(*where).a; } return end(); } U *end() { return &leaf.a; } ll size() { assert(Size == tree.size()); return Size; } U *erase(T key) { node *where = search(key); if (where == err()) { return end(); } if ((*where).key != key) { return end(); } Size--; return &(*erase(where)).a; } void print() { if (Size == 0) { return; } dfs(root); } void dfs(node *where) { assert(where != err()); cout << (*where).key << " " << (*where).priority << endl; if ((*where).right != err()) { dfs((*where).right); } if ((*where).left != err()) { dfs((*where).left); } } void test() { mid_dfs(root); cout << endl; first_dfs(root); cout << endl; } void mid_dfs(node *where) { assert(where != err()); if ((*where).left != err()) { mid_dfs((*where).left); } cout << " " << (*where).a; if ((*where).right != err()) { mid_dfs((*where).right); } } void first_dfs(node *where) { assert(where != err()); cout << " " << (*where).a; if ((*where).left != err()) { first_dfs((*where).left); } if ((*where).right != err()) { first_dfs((*where).right); } } }; int main() { treap<ll, ll> T; ll q; cin >> q; while (q--) { ll com; cin >> com; if (com == 0) { ll x; cin >> x; T.insert(x, x); cout << T.size() << endl; } else if (com == 1) { ll x; cin >> x; if (T.find(x) == T.end()) { cout << 0 << endl; } else { cout << 1 << endl; } } else { ll x; cin >> x; T.erase(x); } } return 0; }
#include <algorithm> #include <cassert> #include <chrono> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 1000000007; template <typename T> class List { private: typedef unsigned long ul; struct node { node *front; node *back; T a; }; ul Size; node *root; node *create(T a) { node *New = (node *)malloc(sizeof(node)); assert(New != NULL); (*New).a = a; return New; } public: struct iterator { node *where; iterator(node *where) : where(where) {} iterator(T *t) { char *C = (char *)t; C -= 2 * sizeof(node *); where = (node *)C; } iterator &operator++() { where = (*where).back; return *this; } iterator &operator--() { where = (*where).front; return *this; } iterator operator++(int) { iterator ret = *this; where = (*where).back; return ret; } iterator operator--(int) { iterator ret = *this; where = (*where).front; return ret; } bool operator==(const iterator &I) const { return where == I.where; } bool operator!=(const iterator &I) const { return where != I.where; } T &operator*() { return (*where).a; } T *pointer() { return &(*where).a; } }; List() { Size = 0; root = create(T()); (*root).back = root; (*root).front = root; } iterator begin() { return iterator((*root).back); } iterator end() { return iterator(root); } ul size() { return Size; } iterator push_back(T a) { node *New = create(a); node *F = (*root).front; (*F).back = New; (*New).front = F; (*root).front = New; (*New).back = root; Size++; return iterator(New); } iterator push_front(T a) { node *New = create(a); node *B = (*root).back; (*root).back = New; (*New).front = root; (*B).front = New; (*New).back = B; Size++; return (New); } iterator pop_back() { if (Size == 0) { return root; } node *E = (*root).front; node *F = (*E).front; (*F).back = root; (*root).front = F; free(E); Size--; return iterator(root); } iterator pop_front() { if (Size == 0) { return root; } node *E = (*root).back; node *B = (*E).back; (*B).front = root; (*root).back = B; free(E); Size--; return iterator(B); } iterator erase(iterator where) { node *E = where.where; if (Size == 0 || E == root) { return iterator(root); } node *F = (*E).front; node *B = (*E).back; (*F).back = B; (*B).front = F; free(E); Size--; return B; } iterator erase(T *where) { return erase(iterator(where)); } iterator erase(node *E) { if (Size == 0 || E == root) { return iterator(root); } node *F = (*E).front; node *B = (*E).back; (*F).back = B; (*B).front = F; free(E); Size--; return B; } }; template <typename T, typename U> class treap { private: struct node { ll priority; T key; U a; node *parent; node *right; node *left; }; random_device r; mt19937 mt; List<node> tree; node *root; node leaf = {0, T(), U(), NULL, NULL, NULL}; ll Size; node *search(T key) { if (Size == 0) { return err(); } node *where = root; while (1) { if ((*where).key == key) { return where; } if ((*where).right != err() && (*where).key < key) { where = (*where).right; continue; } if ((*where).left != err() && key < (*where).key) { where = (*where).left; continue; } return where; } return err(); } node *err() { return &leaf; } ll mk_pr() { uniform_int_distribution<int> R(1, 1000000000); return R(mt); } void parent_change(node &P, node *from, node *to) { if (P.right == from) { P.right = to; return; } else if (P.left == from) { P.left = to; return; } assert(false); } void parent_change(node *P, node *from, node *to) { parent_change(*P, from, to); } node *rotateL(node &where) { node *right = where.right; assert(right != err()); node *L = (*right).left; if (L != err()) { where.right = L; (*L).parent = &where; } else { where.right = err(); } (*right).left = &where; if (where.parent == err()) { root = right; (*right).parent = err(); } else { (*right).parent = where.parent; parent_change((*right).parent, &where, right); } where.parent = right; return right; } node *rotateR(node &where) { node *left = where.left; assert(left != err()); node *R = (*left).right; if (R != err()) { where.left = R; (*R).parent = &where; } else { where.left = err(); } (*left).right = &where; if (where.parent == err()) { root = left; (*left).parent = err(); } else { (*left).parent = where.parent; parent_change((*left).parent, &where, left); } where.parent = left; return left; } node *rotate(node &where) { node *P = where.parent; if (P != err() && (*P).priority < where.priority) { if ((*P).right == &where) { rotateL(*P); } else { rotateR(*P); } } return &where; } node *rotate(node *where) { return rotate(*where); } node *Max(node *where) { assert(where != err()); while (1) { if ((*where).right == err()) { return where; } where = (*where).right; } return err(); } node *Min(node *where) { assert(where != err()); while (1) { if ((*where).left == err()) { return where; } where = (*where).left; } return err(); } node *erase(node *where) { if ((*where).right != err() && (*where).left != err()) { node *ers = Min((*where).right); (*where).key = (*ers).key; (*where).a = (*ers).a; erase(ers); return where; } node *ret; if ((*where).right == err() && (*where).left == err()) { if (where == root) { tree.erase(where); root = err(); return err(); } parent_change((*where).parent, where, err()); ret = (*where).parent; tree.erase(where); } else if ((*where).right != err()) { if (where == root) { root = (*where).right; (*(*where).right).parent = err(); tree.erase(where); return root; } parent_change((*where).parent, where, (*where).right); (*(*where).right).parent = (*where).parent; ret = (*where).parent; tree.erase(where); } else { if (where == root) { root = (*where).left; (*(*where).left).parent = err(); tree.erase(where); return root; } parent_change((*where).parent, where, (*where).left); (*(*where).left).parent = (*where).parent; ret = (*where).parent; tree.erase(where); } return ret; } public: treap() : mt(r()) { Size = 0; root = err(); } void insert(T key, U a) { if (Size == 0) { tree.push_front({mk_pr(), key, a, err(), err(), err()}); Size++; root = &(*tree.begin()); return; } node *where = search(key); if ((*where).key == key) { (*where).a = a; } else { tree.push_front({mk_pr(), key, a, where, err(), err()}); node *New = &(*tree.begin()); if ((*where).key < key) { (*where).right = New; } else { (*where).left = New; } while (New != err()) { New = rotate(New); New = (*New).parent; } Size++; } } U *find(T key) { if (Size == 0) { return end(); } node *where = search(key); if ((*where).key == key) { return &(*where).a; } return end(); } U *end() { return &leaf.a; } ll size() { assert(Size == tree.size()); return Size; } U *erase(T key) { node *where = search(key); if (where == err()) { return end(); } if ((*where).key != key) { return end(); } Size--; return &(*erase(where)).a; } void print() { if (Size == 0) { return; } dfs(root); } void dfs(node *where) { assert(where != err()); cout << (*where).key << " " << (*where).priority << endl; if ((*where).right != err()) { dfs((*where).right); } if ((*where).left != err()) { dfs((*where).left); } } void test() { mid_dfs(root); cout << endl; first_dfs(root); cout << endl; } void mid_dfs(node *where) { assert(where != err()); if ((*where).left != err()) { mid_dfs((*where).left); } cout << " " << (*where).a; if ((*where).right != err()) { mid_dfs((*where).right); } } void first_dfs(node *where) { assert(where != err()); cout << " " << (*where).a; if ((*where).left != err()) { first_dfs((*where).left); } if ((*where).right != err()) { first_dfs((*where).right); } } }; int main() { treap<ll, ll> T; ll q; cin >> q; while (q--) { ll com; cin >> com; if (com == 0) { ll x; cin >> x; T.insert(x, x); cout << T.size() << endl; } else if (com == 1) { ll x; cin >> x; if (T.find(x) == T.end()) { cout << 0 << endl; } else { cout << 1 << endl; } } else { ll x; cin >> x; T.erase(x); } } return 0; }
insert
339
339
339
340
0
p02456
Python
Runtime Error
numset = set([]) q = int(input()) for i in range(q): query, x = list(map(int, input().split(" "))) if query == 0: numset.add(x) print(len(numset)) elif query == 1: if set([x]).issubset(numset): print(1) else: print(0) else: numset.remove(x)
numset = set([]) q = int(input()) for i in range(q): query, x = list(map(int, input().split(" "))) if query == 0: numset.add(x) print(len(numset)) elif query == 1: if set([x]).issubset(numset): print(1) else: print(0) else: if set([x]).issubset(numset): numset.remove(x)
replace
13
14
13
15
0
p02457
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; set<int> st; for (int i = 0; i < q; i++) { int cmd; cin >> cmd; if (cmd == 0) { int x; cin >> x; st.insert(x); cout << st.size() << endl; } if (cmd == 1) { int x; cin >> x; cout << st.count(x) << endl; } if (cmd == 2) { int x; cin >> x; st.erase(x); } if (cmd == 3) { int l, r; cin >> l >> r; for (int i = l; i <= r; i++) { if (st.count(i)) { auto itr = st.find(i); cout << *itr << endl; } } } } }
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; set<int> st; for (int i = 0; i < q; i++) { int cmd; cin >> cmd; if (cmd == 0) { int x; cin >> x; st.insert(x); cout << st.size() << endl; } if (cmd == 1) { int x; cin >> x; cout << st.count(x) << endl; } if (cmd == 2) { int x; cin >> x; st.erase(x); } if (cmd == 3) { int l, r; cin >> l >> r; for (auto itr = st.lower_bound(l), end = st.upper_bound(r); itr != end; itr++) { cout << *itr << endl; } } } }
replace
29
34
29
32
TLE
p02457
C++
Time Limit Exceeded
#include <iterator> #include <set> #include <stdio.h> using namespace std; int main() { int n, temp, k; set<int> s; set<int>::iterator u; scanf("%d", &n); while (n--) { scanf("%d%d", &k, &temp); if (k == 0) { s.insert(temp); printf("%ld\n", s.size()); } else if (k == 1) { if (s.find(temp) == s.end()) printf("0\n"); else printf("1\n"); } else if (k == 2) s.erase(temp); else { u = s.lower_bound(temp); scanf("%d", &temp); while (u != s.end()) { if (*u > temp) break; printf("%d\n", *u); } } } }
#include <iterator> #include <set> #include <stdio.h> using namespace std; int main() { int n, temp, k; set<int> s; set<int>::iterator u; scanf("%d", &n); while (n--) { scanf("%d%d", &k, &temp); if (k == 0) { s.insert(temp); printf("%ld\n", s.size()); } else if (k == 1) { if (s.find(temp) == s.end()) printf("0\n"); else printf("1\n"); } else if (k == 2) s.erase(temp); else { u = s.lower_bound(temp); scanf("%d", &temp); while (u != s.end()) { if (*u > temp) break; printf("%d\n", *u); u++; } } } }
insert
28
28
28
29
TLE
p02457
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main(void) { set<int> S; int q, com, x, y; cin >> q; while (q--) { cin >> com; switch (com) { case 0: cin >> x; S.insert(x); cout << S.size() << endl; break; case 1: cin >> x; if (S.find(x) != S.end()) { cout << "1\n"; } else { cout << "0\n"; } break; case 2: cin >> x; S.erase(x); break; case 3: cin >> x >> y; for (int i = x; i <= y; i++) { if (S.find(i) != S.end()) { cout << i << endl; } } break; } } }
#include <bits/stdc++.h> using namespace std; int main(void) { set<int> S; int q, com, x, y; cin >> q; while (q--) { cin >> com; switch (com) { case 0: cin >> x; S.insert(x); cout << S.size() << endl; break; case 1: cin >> x; if (S.find(x) != S.end()) { cout << "1\n"; } else { cout << "0\n"; } break; case 2: cin >> x; S.erase(x); break; case 3: cin >> x >> y; set<int>::iterator it = S.lower_bound(x); set<int>::iterator end = S.upper_bound(y); while (it != end) { cout << *it << endl; it++; } break; } } }
replace
29
33
29
34
TLE
p02457
C++
Time Limit Exceeded
#include <cassert> #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <cinttypes> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstdbool> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctgmath> #include <ctime> #include <cwchar> #include <cwctype> // C++ #include <algorithm> #include <array> #include <atomic> #include <bitset> #include <chrono> #include <complex> #include <condition_variable> #include <deque> #include <exception> #include <forward_list> #include <fstream> #include <functional> #include <future> #include <initializer_list> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <mutex> #include <new> #include <numeric> #include <ostream> #include <queue> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> // #include <boost/foreach.hpp> // #include <boost/range/algorithm.hpp> #define rep(i, j, k) for (int i = (int)j; i < (int)k; i++) #define ll long long #define Sort(v) sort(all(v)) #define INF 1000000000 #define END return 0 #define pb push_back #define se second #define fi first #define pb push_back #define all(v) (v).begin(), (v).end() #define MP make_pair #define MOD 1000000007LL using namespace std; int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { int q; cin >> q; set<int> st; rep(i, 0, q) { int a, b; cin >> a >> b; if (a == 0) { st.insert(b); cout << st.size() << endl; } else if (a == 1) { cout << ((st.find(b) == st.end()) ? 0 : 1) << endl; } else if (a == 2) { st.erase(b); } else { int r; cin >> r; auto it = lower_bound(all(st), b); for (; it != st.end() && *it <= r; it++) { cout << *it << endl; } } } } /* */
#include <cassert> #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <cinttypes> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstdbool> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctgmath> #include <ctime> #include <cwchar> #include <cwctype> // C++ #include <algorithm> #include <array> #include <atomic> #include <bitset> #include <chrono> #include <complex> #include <condition_variable> #include <deque> #include <exception> #include <forward_list> #include <fstream> #include <functional> #include <future> #include <initializer_list> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <mutex> #include <new> #include <numeric> #include <ostream> #include <queue> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> // #include <boost/foreach.hpp> // #include <boost/range/algorithm.hpp> #define rep(i, j, k) for (int i = (int)j; i < (int)k; i++) #define ll long long #define Sort(v) sort(all(v)) #define INF 1000000000 #define END return 0 #define pb push_back #define se second #define fi first #define pb push_back #define all(v) (v).begin(), (v).end() #define MP make_pair #define MOD 1000000007LL using namespace std; int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { int q; cin >> q; set<int> st; rep(i, 0, q) { int a, b; cin >> a >> b; if (a == 0) { st.insert(b); cout << st.size() << endl; } else if (a == 1) { cout << ((st.find(b) == st.end()) ? 0 : 1) << endl; } else if (a == 2) { st.erase(b); } else { int r; cin >> r; auto it = st.lower_bound(b); for (; it != st.end() && *it <= r; it++) { cout << *it << endl; } } } } /* */
replace
112
113
112
113
TLE
p02457
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <set> using namespace std; int main() { int q, com, x, l, r; set<int> S; cin >> q; for (int i = 0; i < q; i++) { cin >> com; if (com == 0) { cin >> x; S.insert(x); cout << S.size() << endl; } else if (com == 1) { cin >> x; cout << S.count(x) << endl; } else if (com == 2) { cin >> x; S.erase(x); } else if (com == 3) { set<int>::iterator itl, itr; cin >> l >> r; itl = lower_bound(S.begin(), S.end(), l); itr = upper_bound(S.begin(), S.end(), r); for (set<int>::iterator it = itl; it != itr; it++) cout << *it << endl; } } return 0; }
#include <algorithm> #include <iostream> #include <set> using namespace std; int main() { int q, com, x, l, r; set<int> S; cin >> q; for (int i = 0; i < q; i++) { cin >> com; if (com == 0) { cin >> x; S.insert(x); cout << S.size() << endl; } else if (com == 1) { cin >> x; cout << S.count(x) << endl; } else if (com == 2) { cin >> x; S.erase(x); } else if (com == 3) { set<int>::iterator itl, itr; cin >> l >> r; itl = S.lower_bound(l); itr = S.upper_bound(r); for (set<int>::iterator it = itl; it != itr; it++) cout << *it << endl; } } return 0; }
replace
28
30
28
30
TLE
p02457
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) set<int> st; int main() { int q; cin >> q; while (q--) { int Q, k; cin >> Q >> k; if (Q == 0) { st.insert(k); cout << st.size() << endl; } else if (Q == 1) { cout << st.count(k) << endl; } else if (Q == 2) { st.erase(k); } else { int y; cin >> y; auto itr = st.lower_bound(k); while (*itr <= y) { cout << *itr << endl; itr++; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) set<int> st; int main() { int q; cin >> q; while (q--) { int Q, k; cin >> Q >> k; if (Q == 0) { st.insert(k); cout << st.size() << endl; } else if (Q == 1) { cout << st.count(k) << endl; } else if (Q == 2) { st.erase(k); } else { int y; cin >> y; auto nowitr = st.lower_bound(k); auto enditr = st.upper_bound(y); while (nowitr != enditr) { cout << *nowitr << endl; nowitr++; } } } return 0; }
replace
20
24
20
25
TLE
p02460
Python
Runtime Error
dict = {} q = int(input()) for i in range(q): query, *val = input().split(" ") if query == "0": dict[val[0]] = int(val[1]) elif query == "1": print(dict.get(val[0], 0)) else: dict.pop(val[0])
dict = {} q = int(input()) for i in range(q): query, *val = input().split(" ") if query == "0": dict[val[0]] = int(val[1]) elif query == "1": print(dict.get(val[0], 0)) else: if val[0] in dict: dict.pop(val[0])
replace
9
10
9
11
0
p02462
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) multimap<string, int> mp; int main() { int q; cin >> q; while (q--) { int Q; cin >> Q; string s, l, r; int x; if (Q == 0) { cin >> s >> x; mp.insert(make_pair(s, x)); } if (Q == 1) { cin >> s; auto now = mp.lower_bound(s); while (now->first == s && now != mp.end()) { cout << now->second << endl; ++now; } } if (Q == 2) { cin >> s; mp.erase(s); } if (Q == 3) { cin >> l >> r; auto now = mp.lower_bound(l); auto end = mp.upper_bound(r); assert(l <= r); while (now != end) { cout << now->first << " " << now->second << endl; ++now; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) multimap<string, int> mp; int main() { int q; cin >> q; while (q--) { int Q; cin >> Q; string s, l, r; int x; if (Q == 0) { cin >> s >> x; mp.insert(make_pair(s, x)); } if (Q == 1) { cin >> s; for (auto it = mp.lower_bound(s); it != mp.end() && it->first == s; it++) { cout << it->second << endl; } } if (Q == 2) { cin >> s; mp.erase(s); } if (Q == 3) { cin >> l >> r; auto now = mp.lower_bound(l); auto end = mp.upper_bound(r); assert(l <= r); while (now != end) { cout << now->first << " " << now->second << endl; ++now; } } } return 0; }
replace
18
22
18
21
0
p02462
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define Rep(i, a, b) for (int i = a; i < b; i++) #define REP(i, a, b) for (int i = a; i <= b; i++) #define rev(i, n) for (int i = n - 1; i >= 0; i--) #define vi vector<int> #define pb push_back #define pi pair<int, int> #define vp vector<pair<int, int>> #define mp make_pair #define all(v) (v).begin(), (v).end() using namespace std; signed main() { multimap<string, int> map; int q; cin >> q; while (q--) { int y; string k; cin >> y >> k; if (y == 0) { int x; cin >> x; map.insert(pair<string, int>(k, x)); } else if (y == 1) { for (auto it = map.find(k); it->first == k; it++) { cout << it->second << endl; } } else if (y == 2) { map.erase(k); } else { string z; cin >> z; for (auto it = map.lower_bound(k); it != map.upper_bound(z); it++) { cout << it->first << " " << it->second << endl; } } } return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define Rep(i, a, b) for (int i = a; i < b; i++) #define REP(i, a, b) for (int i = a; i <= b; i++) #define rev(i, n) for (int i = n - 1; i >= 0; i--) #define vi vector<int> #define pb push_back #define pi pair<int, int> #define vp vector<pair<int, int>> #define mp make_pair #define all(v) (v).begin(), (v).end() using namespace std; signed main() { multimap<string, int> map; int q; cin >> q; while (q--) { int y; string k; cin >> y >> k; if (y == 0) { int x; cin >> x; map.insert(pair<string, int>(k, x)); } else if (y == 1) { for (auto it = map.find(k); it != map.end() && it->first == k; it++) { cout << it->second << endl; } } else if (y == 2) { map.erase(k); } else { string z; cin >> z; for (auto it = map.lower_bound(k); it != map.upper_bound(z); it++) { cout << it->first << " " << it->second << endl; } } } return 0; }
replace
27
28
27
28
0
p02467
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #include <vector> using namespace std; bool isPrime(int x) { for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return false; return true; } int main() { int n; cin >> n; vector<int> res; int temp = n; for (int i = 2; i <= n; i++) { if (isPrime(i)) while (temp % i == 0) { res.push_back(i); temp /= i; } if (temp == 1) break; } cout << n << ":"; for (int i = 0; i < res.size(); i++) { cout << " "; cout << res[i]; } cout << endl; }
#include <cmath> #include <iostream> #include <vector> using namespace std; bool isPrime(int x) { for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return false; return true; } int main() { int n; cin >> n; vector<int> res; int temp = n; if (isPrime(n)) res.push_back(n); else { for (int i = 2; i <= n; i++) { if (isPrime(i)) while (temp % i == 0) { res.push_back(i); temp /= i; } if (temp == 1) break; } } cout << n << ":"; for (int i = 0; i < res.size(); i++) { cout << " "; cout << res[i]; } cout << endl; }
replace
15
23
15
27
TLE
p02467
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int N; cin >> N; cout << N << ":"; if (N <= 1) { cout << " " << N << endl; return 0; } vector<bool> x(N, true); long long int M = sqrtl(N) + 1; for (size_t i = 2; i <= M; i++) { while (N % i == 0) { cout << " " << i; N /= i; } } if (N != 1) { cout << " " << N; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N; cin >> N; cout << N << ":"; if (N <= 1) { cout << " " << N << endl; return 0; } long long int M = sqrtl(N) + 1; for (size_t i = 2; i <= M; i++) { while (N % i == 0) { cout << " " << i; N /= i; } } if (N != 1) { cout << " " << N; } cout << endl; return 0; }
delete
11
12
11
11
MLE
p02467
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { int n; cin >> n; int nn = n; cout << n << ":"; bool cnt = true; while (1) { if (n % 2 == 0) { cout << " " << 2; n /= 2; cnt = false; } else break; } while (1) { if (n % 3 == 0) { cout << " " << 3; n /= 3; cnt = false; } else break; } for (int i = 3; i <= nn; i += 2) { bool gouseisuu = false; for (int j = 3; j <= i; j += 2) { if (i % j == 0) { gouseisuu = true; break; } if (!gouseisuu) { while (1) { if (n % i == 0) { cout << " " << i; n /= i; cnt = false; } else break; } } } if (n == 1) break; } if (cnt) cout << " " << nn; cout << endl; }
#include <cmath> #include <iostream> using namespace std; int main() { int n; cin >> n; int nn = n; cout << n << ":"; bool cnt = true; while (1) { if (n % 2 == 0) { cout << " " << 2; n /= 2; cnt = false; } else break; } while (1) { if (n % 3 == 0) { cout << " " << 3; n /= 3; cnt = false; } else break; } for (int i = 3; i <= nn; i += 2) { bool gouseisuu = false; for (int j = 3; j <= i; j += 2) { if (i % j == 0) { gouseisuu = true; break; } if (!gouseisuu) { while (1) { if (n % i == 0) { cout << " " << i; n /= i; cnt = false; } else break; } } } if (n == 1) break; if (n == nn && cnt == true && i >= sqrt(n)) break; } if (cnt) cout << " " << nn; cout << endl; }
insert
47
47
47
49
TLE
p02467
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #define MAX_N 100001 using namespace std; bool isPrime(int n) { if (n == 0 || n == 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0) return false; for (int i = 5; i <= sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } int main() { int n; cin >> n; int nc = n; cout << n << ':'; for (int i = 2; i <= nc; i++) { if (isPrime(i) == false) continue; if (nc % i) continue; while (nc % i == 0) { cout << ' ' << i; nc /= i; } } cout << endl; return 0; }
#include <cmath> #include <iostream> #define MAX_N 100001 using namespace std; bool isPrime(int n) { if (n == 0 || n == 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0) return false; for (int i = 5; i <= sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } int main() { int n; cin >> n; int nc = n; cout << n << ':'; if (isPrime(n) == true) { cout << ' ' << n << endl; return 0; } for (int i = 2; i <= nc; i++) { if (isPrime(i) == false) continue; if (nc % i) continue; while (nc % i == 0) { cout << ' ' << i; nc /= i; } } cout << endl; return 0; }
insert
24
24
24
28
TLE
p02467
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> #define int long long using namespace std; signed main() { int n, m; vector<int> v; cin >> n; m = n; for (int i = 2; i <= sqrt(n); i++) { while (m % i == 0) { v.push_back(i); m /= i; } } if (m >= v.back()) v.push_back(m); cout << n << ':'; for (int i : v) cout << ' ' << i; cout << endl; }
#include <cmath> #include <iostream> #include <vector> #define int long long using namespace std; signed main() { int n, m; vector<int> v; cin >> n; m = n; for (int i = 2; i <= sqrt(n); i++) { while (m % i == 0) { v.push_back(i); m /= i; } } if (m != 1) v.push_back(m); cout << n << ':'; for (int i : v) cout << ' ' << i; cout << endl; }
replace
16
17
16
17
0
p02467
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int main() { int a; cin >> a; cout << a << ":"; vector<int> r; int j = 2; while (true) { if (a == 1) { break; } if (a % j == 0) { r.push_back(j); a /= j; } else { j += 1; } } for (int i : r) { cout << ' ' << i; } cout << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int a; cin >> a; cout << a << ":"; vector<int> r; int j = 2; while (true) { if (a == 1) { break; } if (a % j == 0) { r.push_back(j); a /= j; } else { j += 1; } if (j * j > a) { r.push_back(a); break; } } for (int i : r) { cout << ' ' << i; } cout << endl; }
insert
23
23
23
27
TLE
p02467
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; vector<int> factorize; cout << n << ": "; int input = n; for (int i = 2; i <= sqrt((double)input); ++i) { while (n % i == 0) { n /= i; factorize.push_back(i); } } for (int i = 0; i < factorize.size() - 1; ++i) { cout << factorize[i] << " "; } cout << factorize[factorize.size() - 1] << endl; } int main() { solve(); return (0); }
#include <cmath> #include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; vector<int> factorize; cout << n << ": "; int input = n; for (int i = 2; i <= sqrt((double)input); ++i) { while (n % i == 0) { n /= i; factorize.push_back(i); } } if (n != 1) { factorize.push_back(n); } for (int i = 0; i < factorize.size() - 1; ++i) { cout << factorize[i] << " "; } cout << factorize[factorize.size() - 1] << endl; } int main() { solve(); return (0); }
insert
18
18
18
21
0
p02467
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define CIN(in) \ int in; \ cin >> in; #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(), in.end() const double PI = acos(-1); const double ESP = 1e-10; using namespace std; int main() { CIN(in); cout << in << ":"; loop(i, 2, 1e9 + 10) { while (in % i == 0) { cout << " " << i; in /= i; } if (in == 1) break; } cout << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define CIN(in) \ int in; \ cin >> in; #define pb push_back #define mp make_pair #define it ::iterator #define all(in) in.begin(), in.end() const double PI = acos(-1); const double ESP = 1e-10; using namespace std; int main() { CIN(in); cout << in << ":"; loop(i, 2, 1e9 + 10) { if (i * i > in) { cout << " " << in; break; } while (in % i == 0) { cout << " " << i; in /= i; } if (in == 1) break; } cout << endl; }
insert
25
25
25
29
TLE
p02467
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <list> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> #define FOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define INF 1000000000 // 2000000000 #define LLINF 1000000000000000000 // 9000000000000000000 #define PI 3.14159265358979 using namespace std; typedef long long int ll; typedef pair<long long int, long long int> P; int main(void) { int n; int dp[100001]; int pos = 1; cin >> n; cout << n << ":"; FOR(i, 2, n) { while (n % i == 0) { dp[pos] = i; pos++; n /= i; } } FOR(i, 1, pos - 1) { cout << " " << dp[i]; } cout << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <list> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> #define FOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define INF 1000000000 // 2000000000 #define LLINF 1000000000000000000 // 9000000000000000000 #define PI 3.14159265358979 using namespace std; typedef long long int ll; typedef pair<long long int, long long int> P; int main(void) { int n; int dp[100001]; int pos = 1; cin >> n; cout << n << ":"; FOR(i, 2, n) { if (pos == 1 && i > sqrt(n)) { dp[pos] = n; pos++; n = 1; } while (n % i == 0) { dp[pos] = i; pos++; n /= i; } } FOR(i, 1, pos - 1) { cout << " " << dp[i]; } cout << endl; return 0; }
insert
33
33
33
38
TLE
p02467
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; bool isprime(int n) { if (n == 1) return false; if (n == 2) return true; for (int i = 2; i <= sqrt(n) + 1; i++) { if (n % i == 0) return false; } return true; } int main(void) { int h; cin >> h; // int n=h; cout << h << ":"; int n = h; for (int i = 2; i <= h; i++) { if (isprime(i)) { while (n % i == 0) { n /= i; cout << " " << i; } if (isprime(n)) break; } } if (n != 1) cout << " " << n; cout << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; bool isprime(int n) { if (n == 1) return false; if (n == 2) return true; for (int i = 2; i <= sqrt(n) + 1; i++) { if (n % i == 0) return false; } return true; } int main(void) { int h; cin >> h; // int n=h; cout << h << ":"; int n = h; for (int i = 2; i <= sqrt(h) + 1; i++) { if (isprime(i)) { while (n % i == 0) { n /= i; cout << " " << i; } if (isprime(n)) break; } } if (n != 1) cout << " " << n; cout << endl; return 0; }
replace
22
23
22
23
TLE
p02467
C++
Time Limit Exceeded
#include <iostream> using namespace std; bool flag[1000010]; int main() { int n, p; cin >> n; p = n; cout << n << ":"; while (1) { if (n == 1) { cout << endl; break; } for (int i = 2; 1000010; i++) { if (n % i == 0) { cout << " " << i; n /= i; break; } } if (n == p) { cout << " " << p << endl; break; } } }
#include <iostream> using namespace std; bool flag[1000010]; int main() { int n, p; cin >> n; p = n; cout << n << ":"; while (1) { if (n == 1) { cout << endl; break; } for (int i = 2; i < 1000010; i++) { if (n % i == 0) { cout << " " << i; n /= i; break; } } if (n == p) { cout << " " << p << endl; break; } } }
replace
15
16
15
16
TLE