이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// 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;
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
int n, m, mx[mxn], baskan[mxn], wegol[mxn];
int b[mxn];
int sq = 995;
vector<int> v[1000];
int main() {
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> b[i];
v[i / sq].push_back(b[i]);
}
for(int i = 0; i <= (n - 1) / sq; i++){
for(int j = 0; j < v[i].size(); j++){
if(baskan[i] > v[i][j]){
mx[i] = max(mx[i], baskan[i] + v[i][j]);
}
baskan[i] = max(baskan[i], v[i][j]);
wegol[i] = min(wegol[i], v[i][j]);
}
sort(v[i].begin(), v[i].end());
}
for(int i = 1; i <= m; i++){
int l, r, x, batkya = -1;
cin >> l >> r >> x;
l--, r--;
int ans = 0;
while(l <= r){
if(l % sq == 0 && l + sq - 1 <= r){
cout << 1 / 0;
ans = max(ans, mx[l / sq]);
if(batkya > baskan[l / sq]) ans = max(ans, batkya + baskan[l / sq]);
else {
int L = 0, R = v[l / sq].size() - 1;
while(R - L > 1){
int m = (L + R) / 2;
if(batkya > v[l / sq][m]){
L = m;
}else{
R = m;
}
}
int lol = 0;
if(batkya >= v[l / sq][R]) lol = R;
else if(batkya >= v[l / sq][L]) lol = L;
else lol = -OO;
ans = max(ans, batkya + lol);
l += sq;
}
batkya = max(batkya, baskan[l / sq]);
}else{
if(batkya > b[l]){
ans = max(ans, batkya + b[l]);
}
batkya = max(batkya, b[l]);
l++;
}
}
if(ans > x){
cout << 0;
}else{
cout << 1;
}
cout << nl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j = 0; j < v[i].size(); j++){
| ~~^~~~~~~~~~~~~
sortbooks.cpp:81:27: warning: division by zero [-Wdiv-by-zero]
81 | cout << 1 / 0;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |