이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;
const int large = 5e5+5;
vector<pi> bit[large]; //r, val
void binit(){
for(int i = 1; i < large; i++)
bit[i].push_back({-large,0});
}
void add(int pos, int r){
for(; pos < large; pos += pos&-pos)
bit[pos].push_back({r,bit[pos].back().s+1});
}
int sum(int pos, int fr){
int ans = 0;
for(; pos > 0; pos -= pos&-pos){
int l = 0, r = bit[pos].size();
while(r-l > 1){
int mid = (l+r)>>1;
if(bit[pos][mid].f <= fr)
l = mid;
else r = mid;
}
ans += bit[pos][l].s;
}
return ans;
}
int sum(int l1, int l2, int r1, int r2){ //finds from (l1, l2], (r1, r2]
return sum(l2,r2)-sum(l1,r2)-sum(l2,r1)+sum(l1, r1);
}
int n;
void init(int _n, int _a[], int _b[]){
//input stuff
n = _n; //a = _a; b = _b;
binit();
vector<pi> ranges(n); // r,l
for(int i = 0; i < n; i++){
ranges[i] = {_b[i], _a[i]};
}
sort(ranges.begin(), ranges.end()); //increasing r order
for(auto &p: ranges){
add(p.s,p.f);
}
}
int can(int m, int k[]){
//fix input
vector<int> k2;
vector<pair<pi, int>> hchange = {{{0,n+1},0}}; //{x,y}, add at place
for(int i = 0; i < m; i++) k2.push_back(k[i]);
sort(k2.begin(), k2.end(), greater<int>());
for(int i = 0; i < m; i++){
int rem = k2[i];
int rp = k2[i];
while(rem > 0 && !hchange.empty()){
//remove if protected region is no longer valid
if(hchange.back().f.f > k2[i]){
hchange.pop_back(); continue;
}
//find value of current protected region
int ctop = hchange.back().f.s-1, cleft = hchange.back().f.f, cadd = hchange.back().s;
int x = sum(cleft-1, rp, k2[i]-1, ctop)+cadd;
//Move on if current region has too little
if(rem > x){
rem -= x; rp = cleft-1;
hchange.pop_back(); continue;
}
//Current region has just enough
int boval = sum(cleft, rp, k2[i]-1, ctop);
if(rem > boval){
hchange.pop_back();
hchange.push_back({{cleft, k2[i]}, x-rem});
rem = 0; continue;
}
//binary search to find position
int l = cleft+1, r = rp+1;
while(r-l > 1){
int mid = (l+r)>>1;
x = sum(mid-1, rp, k2[i]-1, ctop);
if(x >= rem) l = mid;
else r = mid;
}
x = sum(l-1, rp, k2[i]-1, ctop);
hchange.push_back({{l,k2[i]}, x-rem});
rem = 0;
continue;
}
if(rem > 0) return 0;
}
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
teams.cpp: In function 'int sum(int, int)':
teams.cpp:30:37: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
30 | int l = 0, r = bit[pos].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... |