Submission #344262

#TimeUsernameProblemLanguageResultExecution timeMemory
344262RakhmandHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
34 / 100
3017 ms8172 KiB
// // A.cpp // torelax // // Created by Rakhman on 1/5/21. // #include <cstring> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <queue> #include <cmath> #include <cstdlib> #include <ctime> #include <cassert> #include <iterator> #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); #define S second #define F first #define pb push_back #define nl '\n' #define NL cout << '\n'; #define EX exit(0) #define all(s) s.begin(), s.end() #define no_answer {cout << "NO"; exit(0);} #define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k) const long long mxn = 1e6 + 110; const long long mnn = 1e3 + 2; const long long mod = 1e9 + 7; const long long inf = 1e18; const long long OO = 1e9 + 100; typedef long long llong; typedef unsigned long long ullong; using namespace std; int n, m, mx[1010]; int b[mxn]; int sq = 450; vector<int> v[1010]; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n; i++){ scanf("%d", &b[i]); v[i / sq].push_back(b[i]); } for(int i = 0; i <= (n - 1) / sq; i++){ int kek = 0; for(int j = 0; j < v[i].size(); j++){ if(kek > v[i][j]){ mx[i] = max(mx[i], kek + v[i][j]); } kek = max(kek, v[i][j]); } sort(v[i].begin(), v[i].end()); } for(int i = 1; i <= m; i++){ int l, r, x, batkya = -1; scanf("%d%d%d", &l, &r, &x); l--, r--; int ans = 0; while(l <= r){ if(l % sq == 0 && l + sq - 1 <= r){ ans = max(ans, mx[l / sq]); int lol = lower_bound(v[l / sq].begin(), v[l / sq].end(), batkya) - v[l / sq].begin() - 1; if(lol >= 0) ans = max(ans, batkya + v[l / sq][lol]); batkya = max(batkya, v[l / sq][v[l / sq].size() - 1]); l += sq; }else{ if(batkya > b[l]){ ans = max(ans, batkya + b[l]); } batkya = max(batkya, b[l]); l++; } } if(ans > x){ printf("%d\n", 0); }else{ printf("%d\n", 1); } cout << nl; } }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(int j = 0; j < v[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
sortbooks.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   76 |         scanf("%d%d%d", &l, &r, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...