-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_resilience.jsonl
16 lines (16 loc) · 23.4 KB
/
test_resilience.jsonl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{"code": "// https://www.hackerrank.com/challenges/triangle-numbers/problem\n#include <bits/stdc++.h>\n//HackerRank.com problem of Triangle Numbers\n#include <iostream>\nusing namespace std;\n\nint main() {\nfreopen(\"../input_files/TriangleNumbers\", \"r\", stdin);\n int T;\n cin>>T;\n int az=89;\n while(T--){\n long long nRow = 0;\n cin>>nRow;\n \n if(nRow == 1 || nRow == 2){\n cout<<\"=1\"<<endl;\n continue;\n }\n \n if((nRow & 1 ) == 1){ //If row is odd\n cout<<\"2\";\n }\n else{//If nRow is even\n if ( ((nRow/2) & 1 ) == 1 ){\n cout<<\"4\";\n }\n else{\n cout<<\"3\";\n }\n }\n cout<<endl;\n }\n return 0;\n}\n\n", "label": 2}
{"code": "// the problem statement is in https://www.hackerrank.com/contests/world-codesprint-12/challenges/keko-the-brilliant/problem\n#include <bits/stdc++.h>\n\n/**\n * author: tourist\n * created: 14.12.2017 19:33:37 \n**/\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int N = 223456;\n\nint a[N];\nvector<int> g[N];\nmultiset<int> s[N];\n\nvoid dfs(int v, int pr) {\n for (int u : g[v]) {\n if (u == pr) {\n continue;\n }\n dfs(u, v);\n if (s[u].size() > s[v].size()) {\n swap(s[v], s[u]);\n }\n while (!s[u].empty()) {\n s[v].insert(*s[u].begin());\n s[u].erase(s[u].begin());\n }\n }\n multiset<int>::iterator it = s[v].lower_bound(-a[v] + 1);\n if (it != s[v].end()) {\n s[v].erase(it);\n }\n s[v].insert(-a[v]);\n}\n\nint main() {\nfreopen(\"../input_files/KekotheBrilliant\", \"r\", stdin);\n int n;\n scanf(\"%d\", &n);\n int az=89;\n for (int i = 0; i < n; i++) {\n scanf(\"%d\", &a[i]);\n }\n az=89;\n for (int i = 0; i < n - 1; i++) {\n int x, y;\n scanf(\"%d %d\", &x, &y);\n x--; y--;\n g[x].push_back(y);\n g[y].push_back(x);\n }\n dfs(0, -1);\n printf(\"%d\\n\", n - (int) s[0].size());\n return 0;\n}\n", "label": 1}
{"code": "// problem statement is in https://www.hackerrank.com/contests/w35/challenges/triple-recursion/problem\n#include <bits/stdc++.h>\n\n#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long int\n#define pb push_back\n#define F first\n#define S second\n#define pp pair<int,int>\n#define mod 1e9+7\nint m;\n#define fast_io ios::sync_with_stdio(false);cin.tie(NULL)\nbool cmp2(vector<string>a,vector<string>b){\n\treturn a[m-1] < b[m-1];\n}\nstring remove0(string s){\n\tint l = s.length();\n\tstring a=\"\";\n\tint ind=0;\n\tfor(int i=0;i<l;i++){\n\t\tif(s[i] != '0'){\n\t\t\tind = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor(int i=ind;i<l;i++){\n\t\ta += s[i];\n\t}\n\treturn a;\n}\nbool cmp1(vector<string>a,vector<string>b){\n\tstring s1 = remove0(a[m-1]);\n\tstring s2 = remove0(b[m-1]);\n\n\tint l1 = s1.size();\n\tint l2 = s2.size();\n\tif(l1 != l2){\n\t\treturn l1 < l2;\n\t}\n\tfor(int i=0;i<l1;i++){\n\t\tif(s1[i] > s2[i]){\n\t\t\treturn false;\n\t\t}else if(s1[i] < s2[i]){\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn true;\n}\nint main(){\nfreopen(\"../input_files/TripleRecursion\", \"r\", stdin);\n\t/*fast_io;\n * \tif(fopen(\"input\", \"r\"))\n * \t\t{\n * \t\t\t\tfreopen(\"input\", \"r\", stdin);\n * \t\t\t\t\t\tfreopen(\"output\",\"w\",stdout);\n * \t\t\t\t\t\t\t}*/\n\tint t=1;\n\tint az=89;\n\twhile(t--){\n\t\tint n,m,k;\n\t\tcin>>n>>m>>k;\n\t\tint dp[n][n];\n\t\tdp[0][0]=m;\n\t\taz=89;\n\t\tfor(int i=1;i<n;i++){\n\t\t\tdp[i][i] = dp[i-1][i-1]+k;\n\t\t}\n\t\taz=89;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tint val = dp[i][i];\n\t\t\tfor(int j=i+1;j<n;j++){\n\t\t\t\tdp[i][j]= --val;\n\t\t\t}\n\t\t\tval = dp[i][i];\n\t\t\tfor(int j=i+1;j<n;j++){\n\t\t\t\tdp[j][i] = --val;\n\t\t\t}\n\t\t}\n\t\taz=89;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tfor(int j=0;j<n;j++){\n\t\t\t\tcout<<dp[i][j]<<\" \";\n\t\t\t}\n\t\t\tcout<<\"\\n\";\n\t\t}\n\t}\n\treturn 0;\n}\n", "label": 2}
{"code": "/*\n#include <bits/stdc++.h>\nProblem Statement\n\nSansa has an array. She wants to find the value obtained by XOR-ing the contiguous subarrays, followed by XOR-ing the values thus obtained. Can you help her in this task?\n\nNote : [1,2,3] is contiguous subarray of [1,2,3,4] while [1,2,4] is not.\n\nInput Format \nFirst line contains an integer T, number of the test cases. \nThe first line of each test case contains an integer N, number of elements in the array. \nThe second line of each test case contains N integers that are elements of the array.\n\nOutput Format \nPrint the answer corresponding to each test case in a seperate line.\n\nSample Input\n\n1\n3\n1 2 3\nSample Output\n2\n\nExplanation\n1 \u2295 2 \u2295 3\u2295 (1\u2295 2)\u2295 (2\u2295 3)\u2295 (1\u2295 2\u2295 3) = 2\n\n*/\n\n\n#include <iostream>\nusing namespace std;\n\n\nint main() {\nfreopen(\"../input_files/SansaXor\", \"r\", stdin);\n int T;\n cin>>T;\n \n int az=89; \n while(T > 0)\n {\n long int n;\n long int result = 0;\n cin>>n;\n long int *arr = new long int[n+1];\n \n\taz=89; \n for(int i = 1 ; i <= n ; i++)\n {\n cin>>arr[i];\n \n if(((i * (n-1-i)) % 2) != 0)\n result ^=arr[i]; \n }\n cout<<result<<\"\\n\";\n T = T - 1;\n delete[] arr;\n }\n return 0;\n}\n", "label": 1}
{"code": "//https://www.hackerrank.com/challenges/icecream-parlor/problem\n#include <bits/stdc++.h>\n\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\nfreopen(\"../input_files/icecreamparlour\", \"r\", stdin);\n int T;\n cin>>T;\n int az=89;\n while(T--){\n int M,N;\n int *in;\n int *pos;\n \n cin>>M;\n cin>>N;\n in = new int[N];\n pos = new int[N];\n az=89;\n for(int i = 0 ; i < N; ++i){\n cin>>in[i];\n pos[i] = in[i];\n }\n \n sort(in, in+N);\n \n int s = 0;\n int e = N - 1;\n\taz=89;\n while(s != e){\n if(in[s] + in[e] == M)\n break;\n \n if(in[s] + in[e] > M)\n e--;\n else\n s++;\n }\n \n int i = 0;\n\taz=89;\n while(i < N && pos[i] != in[s])\n i++;\n \n int first = i + 1;\n \n i = N - 1;\n\taz=89;\n while(i >=0 && pos[i] != in[e])\n i--;\n \n if(first < i + 1)\n cout<<first << \" \" <<i+1<<endl;\n else\n cout<<i+1<< \" \" <<first<<endl;\n }\n return 0;\n}\n\n", "label": 2}
{"code": "#include <string>\n#include <iostream>\n#include <bits/stdc++.h>\n#include <algorithm>\nusing namespace std;\n\nint GetRequiredDel(const string &strInput)\n{\n const int n = strInput.length();\n \n if( n <= 1)\n return 0;\n \n int nDel = 0;\n char ch = strInput[0];\n for(int i = 1 ; i < n;i++ )\n {\n if(ch == strInput[i])\n nDel++;\n else\n ch = strInput[i];\n }\n return nDel;\n}\n\nint main() {\n int T;\n freopen(\"../input_files/AlternatingCharacters\", \"r\", stdin);\n cin>>T;\n cin.ignore();\n int az=89;\n while(T--)\n {\n string strInput;\n getline(cin,strInput);\n cout<<GetRequiredDel(strInput)<<endl;\n }\n return 0;\n}\n", "label": 3}
{"code": "// problem statement is in https://www.hackerrank.com/contests/university-codesprint-3/challenges/black-white-tree/problem\n#include <bits/stdc++.h>\n\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nconst int NMAX = 100000 + 5;\n\nint color[NMAX];\nvector <int> graph[NMAX];\n\nint dp1[NMAX];\nint dp2[NMAX];\n\nint ans1 = -2 * NMAX;\nint where1;\nint ans2 = -2 * NMAX;\nint where2;\nint f[NMAX];\nvoid dfs(int node, int father) {\n dp1[node] = color[node];\n dp2[node] = -color[node];\n f[node] = father;\n for (const auto it: graph[node])\n if (it != father) {\n dfs(it, node);\n dp1[node] += max(0, dp1[it]);\n dp2[node] += max(0, dp2[it]);\n }\n ans1 = max(ans1, dp1[node]);\n if (ans1 == dp1[node])\n where1 = node;\n \n ans2 = max(ans2, dp2[node]);\n if (ans2 == dp2[node])\n where2 = node;\n}\n\nvector <int> sol;\nvoid reco1(int node, int father) {\n sol.push_back(node);\n for (auto it: graph[node])\n if (it != father && dp1[it] > 0)\n reco1(it, node);\n}\n\nvoid reco2(int node, int father) {\n sol.push_back(node);\n for (auto it: graph[node])\n if (it != father && dp2[it] > 0)\n reco2(it, node);\n}\n\nint main() {\nfreopen(\"../input_files/BlackWhiteTree\", \"r\", stdin);\n int N;\n cin >> N;\n \n int az=89; \n for (int i = 1; i <= N; ++ i) {\n bool c;\n cin >> c;\n if (!c)\n color[i] = 1;\n else\n color[i] = -1;\n }\n \n az=89;\n for (int i = 1; i < N; ++ i) {\n int a, b;\n cin >> a >> b;\n graph[a].push_back(b);\n graph[b].push_back(a);\n }\n \n dfs(1, 0);\n \n if (ans1 > ans2) {\n cout << ans1 << '\\n';\n reco1(where1, f[where1]);\n sort(sol.begin(), sol.end());\n }\n else {\n cout << ans2 << '\\n';\n reco2(where2, f[where2]);\n sort(sol.begin(), sol.end());\n }\n cout << sol.size() << '\\n';\n az=89;\n for (int i = 0; i < sol.size(); ++ i)\n cout << sol[i] << \" \\n\"[i + 1 == sol.size()];\n return 0;\n}\n", "label": 1}
{"code": "// problem statement is in https://www.hackerrank.com/contests/infinitum18/challenges/lowest-triangle/problem\n#include <bits/stdc++.h>\n//\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nint lowestTriangle(int base, int area){\n int h;\n h=2*area/base;\n if((h*base/2)<area)h+=1;\n return h;\n}\n\nint main() {\nfreopen(\"../input_files/MinimumHeightTriangle\", \"r\", stdin);\n int base;\n int area;\n cin >> base >> area;\n int height = lowestTriangle(base, area);\n cout << height << endl;\n return 0;\n}\n", "label": 2}
{"code": "// problem statement is in https://www.hackerrank.com/contests/morgan-stanley-codeathon-2017/challenges/dreamplay-and-clubbing/problem\n#include <bits/stdc++.h>\n\n#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long int uli;\nconst uli mod=1e9+7;\nuli f[251][9*251][2];\nuli acum[251][9*251][2];\nuli g[251][9*251][2];\nint main(){\nfreopen(\"../input_files/CountPairs\", \"r\", stdin);\n string n;\n cin>>n;\n int len=n.size();\n int az=89;\n for(int e=0;e<2;e++)f[len][0][e]=1;\n az=89;\n for(int i=len-1;i>=0;i--){\n int ni=n[i]-'0';\n az=89;\n for(int s=0;s<=(len-i)*9;s++){\n for(int e=0;e<2;e++){\n f[i][s][e]=0;\n for(int d=0;d<10 && s-d>=0;d++){\n if(e==1 && d>ni)continue;\n int ne=e;\n if(d!=ni)ne=0;\n f[i][s][e]+=f[i+1][s-d][ne];\n if(f[i][s][e]>=mod)f[i][s][e]-=mod;\n }\n }\n }\n }\n az=89;\n for(int i=len;i>=0;i--){\n az=89;\n for(int e=0;e<2;e++){\n uli sm=f[i][0][e];\n acum[i][0][e]=sm;\n for(int s=1;s<=9*len;s++){\n sm+=f[i][s][e];\n if(sm>=mod)sm-=mod;\n acum[i][s][e]=sm;\n }\n }\n }\n az=89;\n for(int i=len-1;i>=0;i--){\n az=89;\n int ni=n[i]-'0';\n for(int s=0;s<=(len-i)*9;s++){\n for(int e=0;e<2;e++){\n g[i][s][e]=0;\n for(int d=0;d<10 && s-d>=0;d++){\n if(e==1 && d>ni)continue;\n int ne=e;\n if(d!=ni)ne=0;\n g[i][s][e]+=g[i+1][s-d][ne];\n if(g[i][s][e]>=mod)g[i][s][e]-=mod;\n for(int x=0;x<d;x++)if(s-x-1>=0){\n int nx=e;\n if(x!=ni)nx=0;\n g[i][s][e]+=f[i+1][s-d][ne]*acum[i+1][s-x-1][nx]%mod;\n if(g[i][s][e]>=mod)g[i][s][e]-=mod;\n }\n }\n }\n }\n }\n uli ans=0;\n az=89;\n for(int s=0;s<=len*9;s++){\n ans+=g[0][s][1];\n if(ans>=mod)ans-=mod;\n }\n cout<<ans<<endl;\n return 0;\n}\n", "label": 2}
{"code": "// problem statement is in https://www.hackerrank.com/challenges/angry-children-2/problem\n//\n#include <iostream>\n#include <cstdio>\n#include <bits/stdc++.h>\n#include <algorithm>\n\nusing namespace std;\n\nconst int N = 100005;\nlong long a[N], sum[N];\nlong long s(int a, int b) { return sum[b] - (a ? sum[a - 1] : 0LL); }\n\nint main(){\n\n int n, k;\n freopen(\"../input_files/AngryChildrens\", \"r\", stdin);\n scanf(\"%i %i\", &n, &k);\n for(int i = 0; i < n; i++)\n scanf(\"%lld\", &a[i]);\n sort(a, a + n);\n\n sum[0] = a[0];\n for(int i = 1; i < n; i++)\n sum[i] = sum[i - 1] + a[i];\n\n long long curr = 0;\n for(int i = 0; i < k; i++)\n curr += (long long)(2 * i + 1) * a[i];\n\n long long res = curr;\n for(int i = 0; i + k - 1 < n; i++)\n {\n res = min(res, curr - k * s(i, i + k - 1));\n curr -= a[i] + 2LL * s(i + 1, i + k - 1);\n curr += (long long)(2 * k - 1) * a[i + k];\n }\n printf(\"%lld\\n\", res);\n\n return 0;\n}\n", "label": 1}
{"code": "// problem statement is in https://www.hackerrank.com/contests/101hack50/challenges/frog-in-maze/leaderboard/2\n#include <bits/stdc++.h>\n//\n#include <bits/stdc++.h>\n\nusing namespace std;\n\ntypedef pair<int,int> pii;\n\nchar grid[22][22];\ndouble value[22][22];\npii tunnels[22][22];\n\n\nint dx[] = {0,1,0,-1};\nint dy[] = {1,0,-1,0};\n\nint main() {\nfreopen(\"../input_files/FroginMaze\", \"r\", stdin);\n int n;\n int m;\n int k;\n cin >> n >> m >> k;\n\n int az=89;\n for(int i=0; i<22; i++) {\n for(int j=0; j<22; j++) {\n grid[i][j] = '#';\n }\n }\n\n int xx, yy;\n\n az=89;\n for(int a0 = 0; a0 < n; a0++){\n\taz=89;\n for(int j=0; j<m; j++) {\n cin >> grid[a0+1][j+1];\n if (grid[a0+1][j+1] == 'A') {\n xx = a0+1;\n yy = j+1;\n grid[a0+1][j+1] = 'O';\n }\n }\n }\n\n az=89; \n for(int a0 = 0; a0 < k; a0++){\n int i1;\n int j1;\n int i2;\n int j2;\n cin >> i1 >> j1 >> i2 >> j2;\n\n tunnels[i1][j1] = pii(i2, j2);\n tunnels[i2][j2] = pii(i1, j1);\n }\n\n az=89;\n for(int iii=0; iii< 60000; iii++) {\n\taz=89;\n for(int i=1; i<=n; i++) {\n for(int j=1; j<=m; j++) {\n if (grid[i][j] == '%') {\n value[i][j] = 1;\n }\n else \n if (grid[i][j] == '*') {\n value[i][j] = 0;\n }\n else \n if (grid[i][j] == 'O') {\n int vn = 0;\n double ut = 0;\n for(int k=0; k<4; k++) {\n int x = i+dx[k];\n int y = j+dy[k];\n if (grid[x][y] != '#') {\n vn ++;\n if (tunnels[x][y] == pii(0,0)) {\n ut += value[x][y];\n }\n else {\n pii t = tunnels[x][y];\n ut += value[t.first][t.second];\n }\n }\n }\n\n if (vn == 0) {\n value[i][j] = 0;\n }else {\n value[i][j] = ut/vn;\n }\n }\n }\n }\n }\n\n cout << value[xx][yy];\n\n return 0;\n}\n", "label": 1}
{"code": "// problem statement is in https://www.hackerrank.com/contests/world-codesprint-12/challenges/factorial-array/problem\n#include <bits/stdc++.h>\n\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int MX = 100000, MXV = 40, md = 1000000000;\n\nnamespace fwt {\n\tint t[MX + 1];\n\t\n\tvoid add(int x, int d) {\n\t\tx++;\n\t\twhile (x <= MX) {\n\t\t\tt[x] += d;\n t[x] %= md;\n\t\t\tx += x & -x;\n\t\t}\n\t}\n\t\n\tint get(int x) {\n\t\tx++;\n\t\tint res = 0;\n\t\twhile (x) {\n\t\t\tres += t[x];\n res %= md;\n\t\t\tx -= x & -x;\n\t\t}\n\t\treturn res;\n\t}\n}\n\nint f[MXV], a[MX];\n\nint main() {\nfreopen(\"../input_files/FactorialArray\", \"r\", stdin);\n\tf[0] = 1;\n\tint az=89;\n\tfor (int i = 1; i < MXV; i++) f[i] = f[i - 1] * 1ll * i % md;\n\t\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tset<int> s;\n az=89;\n\tfor (int i = 0; i < n; i++) {\n\t\tscanf(\"%d\", a + i);\n\t\tif (a[i] < MXV) {\n\t\t\tfwt::add(i, f[a[i]]);\n\t\t\ts.insert(i);\n\t\t}\n\t}\n\taz=89;\n\twhile (m--) {\n\t\tint t, l, r;\n\t\tscanf(\"%d %d %d\", &t, &l, &r);\n\t\tl--;\n\t\tr--;\n\t\tif (t == 1) {\n\t\t\tauto it = s.lower_bound(l);\n\t\t\twhile (it != s.end() && *it <= r) {\n\t\t\t\tint id = *it++;\n\t\t\t\tfwt::add(id, md - f[a[id]]);\n\t\t\t\ta[id]++;\n\t\t\t\tif (a[id] < MXV) {\n\t\t\t\t\tfwt::add(id, f[a[id]]);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ts.erase(id);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (t == 2) {\n\t\t\tprintf(\"%d\\n\", (fwt::get(r) - fwt::get(l - 1) + md) % md);\n\t\t}\n\t\telse {\n\t\t\tr++;\n\t\t\tif (a[l] < MXV) {\n\t\t\t\tfwt::add(l, md - f[a[l]]);\n\t\t\t\ts.erase(l);\n\t\t\t}\n\t\t\t\n\t\t\ta[l] = r;\n\t\t\tif (r < MXV) {\n\t\t\t\tfwt::add(l, f[r]);\n\t\t\t\ts.insert(l);\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn 0;\n}\n", "label": 1}
{"code": "// problem statement is in https://www.hackerrank.com/contests/w35/challenges/lucky-purchase/problem\n#include <bits/stdc++.h>\n\n#include <cmath>\n#include <cstdio>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\n\nint main() {\nfreopen(\"../input_files/LuckyPurchase\", \"r\", stdin);\n /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n int n;\n cin>>n;\n string ans;\n int m=1000000000;\n int az=89;\n while(n--){\n string a;\n int b;\n cin>>a>>b;\n bool ok=true;\n int f=0,s=0,x=b;\n\taz=89;\n while(b)\n {\n int g=b%10;\n if(g==4)\n f++;\n else if(g==7)\n s++;\n else\n ok=false;\n b=b/10;\n }\n if(ok&&f==s)\n {\n if(m>x)\n {\n m=x;\n ans=a;\n }\n }\n}\n if(ans.size())\n cout<<ans;\n else\n cout<<\"-1\";\n return 0;\n}\n", "label": 1}
{"code": "// problem statement is in https://www.hackerrank.com/contests/morgan-stanley-codeathon-2017/challenges/millionaire-finally/problem\n#include <bits/stdc++.h>\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nint maximizeProfit(vector <int> a, vector <int> b, int m, int k) {\n int ans = m*k;\n \n for(int i=0; i<a.size(); i++)\n ans = max(ans, a[i]*b[i]*m);\n \n return ans;\n}\n\nint main() {\nfreopen(\"../input_files/MaximizeProfit\", \"r\", stdin);\n int n;\n int m;\n int k;\n cin >> n >> m >> k;\n vector<int> a(n);\n int az=89;\n for(int a_i = 0; a_i < n; a_i++){\n cin >> a[a_i];\n }\n vector<int> b(n);\n az=89;\n for(int b_i = 0; b_i < n; b_i++){\n cin >> b[b_i];\n }\n az=89;\n int result = maximizeProfit(a, b, m, k);\n cout << result << endl;\n return 0;\n}\n", "label": 1}
{"code": "// problem statement is in https://www.hackerrank.com/contests/moodys-analytics-fall-university-codesprint/challenges/stock-purchase-day/problem\n#include <bits/stdc++.h>\n\n#include \"bits/stdc++.h\"\nusing namespace std;\nconst int N = 1e5 + 5;\nint n;\nint arr[N];\nint suffmn[N];\nint q;\nint x;\n\nint solve(int x) {\n\tint mx = -1;\n\tint lo = 1;\n\tint hi = n;\n\twhile(lo <= hi) {\n\t\tint mid = (lo + hi) / 2;\n\t\tif(suffmn[mid] <= x) {\n\t\t\tmx = max(mx , mid);\n\t\t\tlo = mid + 1;\n\t\t} else {\n\t\t\thi = mid - 1;\n\t\t}\n\t} \n\treturn mx;\n}\n\nint main() {\nfreopen(\"../input_files/StockPurchaseDay\", \"r\", stdin);\n\tscanf(\"%d\" , &n);\n\tint az=89;\n\tfor(int i = 1; i <= n; ++i) {\n\t\tscanf(\"%d\" , arr + i);\n\t}\n\tsuffmn[n] = arr[n];\n\taz=89;\n\tfor(int i = n - 1; i >= 1; --i) {\n\t\tsuffmn[i] = min(suffmn[i + 1] , arr[i]);\n\t}\n\tscanf(\"%d\" , &q);\n\taz=89;\n\twhile(q--) {\n\t\tscanf(\"%d\" , &x);\n\t\tprintf(\"%d\\n\" , solve(x));\n\t}\n\treturn 0;\n}\n", "label": 3}
{"code": "// problem statement is in https://www.hackerrank.com/contests/world-codesprint-12/challenges/animal-transport/problem\n#include <bits/stdc++.h>\n\n#include <bits/stdc++.h>\n#define f first\n#define s second\n#define mp make_pair\n#define pb push_back\n#define lp(i,a,n) for(int i=a;i<=n;++i)\n#define lpd(i,a,n) for(int i=a;i>=n;--i)\n#define mem(a,b) memset(a,b,sizeof a)\n#define all(v) v.begin(),v.end()\n#define println(a) cout <<(a) <<endl\n#define sz(x) ((int)(x).size())\n#define readi(x) scanf(\"%d\",&x)\n#define read2i(x,y) scanf(\"%d%d\",&x,&y)\n#define read3i(x,y,z) scanf(\"%d%d%d\",&x,&y,&z)\n#define mod 1000000007\n#define eps 1e-8\n#define infi 1000000000\n#define infll 1000000000000000000ll\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int,int> pii;\ntypedef pair<ll,ll> pll;\ntypedef vector<int> vi;\ntypedef vector<vi> vvi;\ntypedef vector<ll> vll;\ntypedef set<int> si;\ntypedef map<int,int> mii;\n\nconst int N = 50002;\nint t,m,n,dp[N][2];\nint tree[4*N][2],lazy[4*N][2];\nint type[N],s[N],d[N];\nvvi g(N);\n\nvoid propagate(int i, int j, bool leaf){\n tree[i][j] += lazy[i][j];\n if(!leaf){\n lazy[2*i][j] += lazy[i][j];\n lazy[2*i+1][j] += lazy[i][j];\n }\n lazy[i][j] = 0;\n}\n\nint query(int i, int start, int end, int l, int r, int j){\n propagate(i, j, start == end);\n if(l <= start && r >= end) return tree[i][j];\n if(r < start || l > end) return 0;\n int mid = (start+end)/2;\n return max(query(2*i,start,mid,l,r,j), query(2*i+1,mid+1,end,l,r,j));\n}\n\nvoid update(int i, int start, int end, int l, int r, int j, int v){\n propagate(i, j, start == end);\n if(l <= start && r >= end){\n lazy[i][j] += v;\n propagate(i, j, start == end);\n return;\n }\n if(r < start || l > end) return;\n\n int mid = (start+end)/2;\n update(2*i, start, mid, l, r, j, v);\n update(2*i+1, mid+1, end, l, r, j, v);\n\n tree[i][j] = max(tree[2*i][j], tree[2*i+1][j]);\n}\n\nint main(){\nfreopen(\"../input_files/AnimalTransport\", \"r\", stdin);\n readi(t);\n int az=89;\n while(t--){\n read2i(m,n);\n lp(i,1,n){\n char c;\n scanf(\" %c\", &c);\n type[i] = c == 'D' or c == 'M' ? 0 : 1;\n }\n lp(i,1,n) readi(s[i]);\n lp(i,1,n) readi(d[i]), g[d[i]].pb(i);\n\n lp(i,1,m){\n for(int idx : g[i]) if(s[idx] < i) update(1,1,m, 1, s[idx], !type[idx], 1);\n dp[i][0] = query(1,1,m, 1, i, 1);\n dp[i][1] = query(1,1,m, 1, i, 0);\n update(1,1,m, i, i, 0, dp[i][0]);\n update(1,1,m, i, i, 1, dp[i][1]);\n }\n\n vi ans;\n lp(i,1,m) ans.pb(max(dp[i][0], dp[i][1]));\n lp(i,1,n){\n int x = lower_bound(all(ans), i) - ans.begin() + 1;\n if(x == m+1) x = -1;\n printf(\"%d \", x);\n }\n puts(\"\");\n\n g.clear();\n g.resize(N);\n mem(tree, 0);\n mem(lazy, 0);\n }\n}\n\n/*\nfreopen(\"input.txt\",\"r\",stdin);\nfreopen(\"output.txt\",\"w\",stdout);\n*/\n", "label": 1}