이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
// mt19937_64 rng(69);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int INF = 1e9 + 69;
struct FenwickTree{
int n;
vector<vector<int>> a;
vector<vector<int>> val;
FenwickTree(int _n){
n = _n;
a.resize(n + 1); val.resize(n + 1);
}
void fake_update(int i, int j){
while(i <= n){
val[i].push_back(j);
i += LASTBIT(i);
}
}
void build_tree(){
for(int i = 1; i<=n; ++i) {
val[i].push_back(-INF);
remove_dup(val[i]);
a[i].resize(val[i].size());
}
}
void update(int i, int j, int v){
while(i <= n){
int idx = lower_bound(ALL(val[i]), j) - val[i].begin();
while(idx < val[i].size()){
a[i][idx] += v;
idx += LASTBIT(idx);
}
i += LASTBIT(i);
}
}
int get(int i, int j){
int ans = 0;
while(i > 0){
int idx = upper_bound(ALL(val[i]), j) - val[i].begin() - 1;
while(idx > 0){
ans += a[i][idx];
idx -= LASTBIT(idx);
}
i -= LASTBIT(i);
}
return ans;
}
};
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
vector<array<int, 2>> a(n);
for(int i = 0; i<n; ++i) for(int &j: a[i]) {
cin >> j;
j *= -1;
}
vector<array<int, 4>> query(q);
for(int i = 0; i<q; ++i) {
query[i][3] = i;
for(int t = 0; t < 3; ++t) {
int &j = query[i][t];
cin >> j;
j *= -1;
}
}
vector<int> b;
for(int i = 0; i<n; ++i) b.push_back(a[i][0]);
remove_dup(b);
FenwickTree bit(b.size());
for(int i = 0; i<n; ++i){
int idx = lower_bound(ALL(b), a[i][0]) - b.begin() + 1;
bit.fake_update(idx, a[i][1]);
}
bit.build_tree();
sort(ALL(a), [] (array<int, 2> x, array<int, 2> y) {return x[0] + x[1] > y[0] + y[1];});
sort(ALL(query), [] (array<int, 4> x, array<int, 4> y) {return x[2] > y[2];});
// for(auto i: a) printArr(i);
// for(auto i: query) printArr(i);
vector<int> ans(q);
while(query.size()){
if (a.size() && a.back()[0] + a.back()[1] <= query.back()[2]){
int idx = lower_bound(ALL(b), a.back()[0]) - b.begin() + 1;
bit.update(idx, a.back()[1], 1);
a.pop_back();
}
else{
int idx = upper_bound(ALL(b), query.back()[0]) - b.begin();
ans[query.back()[3]] = bit.get(idx, query.back()[1]);
query.pop_back();
}
}
printArr(ans, "\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
examination.cpp: In member function 'void FenwickTree::update(int, int, int)':
examination.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while(idx < val[i].size()){
| ~~~~^~~~~~~~~~~~~~~
# | 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... |