QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133154 | #6630. Triangle Collection | PCTprobability# | Compile Error | / | / | C++14 | 10.5kb | 2023-08-01 16:35:36 | 2024-07-04 01:06:57 |
Judging History
你现在查看的是最新测评结果
- [2024-07-04 01:06:57]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-08-01 16:35:36]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define endl "\n"
typedef pair<int, int> Pii;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(s) (s).begin(),(s).end()
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define FOR_(n) for (ll _ = 0; (_) < (ll)(n); ++(_))
#define FOR(i, n) for (ll i = 0; (i) < (ll)(n); ++(i))
#define se second
#define pb push_back
#define P pair<ll,ll>
#define PQminll priority_queue<ll, vector<ll>, greater<ll>>
#define PQmaxll priority_queue<ll,vector<ll>,less<ll>>
#define PQminP priority_queue<P, vector<P>, greater<P>>
#define PQmaxP priority_queue<P,vector<P>,less<P>>
#define NP next_permutation
//const ll mod = 1000000009;
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 4100000000000000000ll;
const ld eps = ld(0.00000000001);
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
#define FOR_R(i, n) for (ll i = (ll)(n)-1; (i) >= 0; --(i))
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a,const T b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a,const T b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
ll fastgcd(ll u,ll v){ll shl=0;while(u&&v&&u!=v){bool eu=!(u&1);bool ev=!(v&1);if(eu&&ev){++shl;u>>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<<shl:u<<shl;}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
ll pop(ll x){return __builtin_popcountll(x);}
ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;}
P hyou(P a){ll x=fastgcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;}
P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});}
P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});}
P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});}
P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});}
P Pgyaku(P a){ return hyou({a.se,a.fi});}
template<class T>
struct Sum{
vector<T> data;
Sum(const vector<T>& v):data(v.size()+1){
for(ll i=0;i<v.size();i++) data[i+1]=data[i]+v[i];
}
T get(ll l,ll r) const {
return data[r]-data[l];
}
};
template<class T>
struct Sum2{
vector<vector<T>> data;
Sum2(const vector<vector<T>> &v):data(v.size()+1,vector<T>(v[0].size()+1)){
for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]=data[i][j+1]+v[i][j];
for(int i=0;i<v.size();i++) for(int j=0;j<v[i].size();j++) data[i+1][j+1]+=data[i+1][j];
}
T get(ll x1,ll y1,ll x2,ll y2) const {
return data[x2][y2]+data[x1][y1]-data[x1][y2]-data[x2][y1];
}
};
void cincout(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(15);
}
struct Segtree{
vector<ll> node,lazy;
ll n;
Segtree(vector<ll> a){
ll N=a.size();
n=1;
while(n<N) n*=2;
node.resize(2*n);
lazy.resize(2*n);
for(int i=0;i<a.size();i++) node[i+n]=a[i];
for(int i=n-1;i>=1;i--) node[i]=min(node[2*i],node[2*i+1]);
}
void eval(ll k){
if(lazy[k]==0) return;
if(k<=n-1){
lazy[2*k]=lazy[2*k]+lazy[k];
lazy[2*k+1]=lazy[2*k+1]+lazy[k];
}
node[k]=node[k]+lazy[k];
lazy[k]=0;
}
void add(int l,int r,int a,int b,int k,int x){
eval(k);
if(r<=a||b<=l) return;
if(l<=a&&b<=r){
lazy[k]+=x;
eval(k);
}
else{
add(l,r,a,(a+b)/2,2*k,x);
add(l,r,(a+b)/2,b,2*k+1,x);
node[k]=min(node[2*k],node[2*k+1]);
}
}
void add(int l,int r,int x){
add(l,r,0,n,1,x);
}
ll get(int l,int r,int a,int b,int k){
eval(k);
if(r<=a||b<=l) return inf;
if(l<=a&&b<=r){
return node[k];
}
else{
return min(get(l,r,a,(a+b)/2,2*k),get(l,r,(a+b)/2,b,2*k+1));
}
}
ll get(int l,int r){
return get(l,r,0,n,1);
}
};
int main() {
cincout();
ll n,q;
cin>>n>>q;
vector<ll> a(n+1);
for(int i=1;i<=n;i++) cin>>a[i];
if(n<=2000&&q<=2000){
for(int _=0;_<q;_++){
ll x,d;
cin>>x>>d;
a[x]+=d;
ll ok=0,ng=0;
for(int i=1;i<=n;i++) ng+=a[i]/2;
ng++;
while(abs(ok-ng)>1){
ll m=(ok+ng)/2;
ll k=m;
for(int i=n;i>=0;i--){
if(k>=a[i]/2){
b[i]=a[i]-(a[i]/2)*2;
c[i]=a[i]/2;
k-=a[i]/2;
}
else{
b[i]=a[i]-2*k;
c[i]=k;
k=0;
}
}
ll p=0;
ll q=0;
bool check=true;
while(q<=n){
while(c[q]){
if(p>q*2-1||p>n){
check=false;
break;
}
ll use=min(c[q],b[p]);
c[q]-=use;
b[p]-=use;
if(b[p]==0) p++;
}
if(!check) break;
q++;
}
if(check) ok=m;
else ng=m;
}
cout<<ok<<endl;
}
return 0;
}
vector<ll> b(n+1),c(n+1);
for(int _=0;_<1;_++){
ll x,d;
cin>>x>>d;
a[x]+=d;
ll ok=0,ng=0;
for(int i=1;i<=n;i++) ng+=a[i]/2;
ng++;
while(abs(ok-ng)>1){
ll m=(ok+ng)/2;
ll k=m;
for(int i=n;i>=0;i--){
if(k>=a[i]/2){
b[i]=a[i]-(a[i]/2)*2;
c[i]=a[i]/2;
k-=a[i]/2;
}
else{
b[i]=a[i]-2*k;
c[i]=k;
k=0;
}
}
ll p=0;
ll q=0;
bool check=true;
while(q<=n){
while(c[q]){
if(p>q*2-1||p>n){
check=false;
break;
}
ll use=min(c[q],b[p]);
c[q]-=use;
b[p]-=use;
if(b[p]==0) p++;
}
if(!check) break;
q++;
}
if(check) ok=m;
else ng=m;
}
cout<<ok<<endl;
while(true){
ll m=ok;
ll k=m;
for(int i=n;i>=0;i--){
if(k>=a[i]/2){
b[i]=a[i]-(a[i]/2)*2;
c[i]=a[i]/2;
k-=a[i]/2;
}
else{
b[i]=a[i]-2*k;
c[i]=k;
k=0;
}
}
break;
}
}
set<ll> ps,nb;
for(int i=0;i<=n;i++) if(c[i]) ps.insert(i);
for(int i=0;i<=n;i++) if(b[i]>=2) nb.insert(i);
bool ok=true;
vector<ll> d(2*n+1);
for(int i=0;i<=n;i++) d[i]+=b[i];
for(int i=0;i<=n;i++) d[2*i-1]-=c[i];
for(int i=1;i<=2*n;i++) d[i]+=d[i-1];
Segtree seg(d);
/* for(auto e:d) cout<<e<<" ";
cout<<endl;
for(int i=0;i<2*n+1;i++) cout<<seg.get(i,i+1)<<" ";
cout<<endl;*/
ll sumc=0;
for(auto e:c) sumc+=e;
auto badd = [&](int x){
b[x]++;
seg.add(x,2*n+1,1);
if(b[x]>=2) nb.insert(x);
};
auto berase = [&](int x){
if(b[x]){
b[x]--;
seg.add(x,2*n+1,-1);
if(b[x]<=1) nb.erase(x);
}
else{
c[x]--;
sumc--;
b[x]++;
seg.add(x,2*n+1,1);
seg.add(2*x-1,2*n+1,1);
if(c[x]==0) ps.erase(x);
if(b[x]>=2) nb.insert(x);
}
};
auto padd = [&](){
ok=true;
if(nb.size()==0){
ok=false;
return;
}
auto itr=nb.end();
itr--;
ll v=(*itr);
// cout<<"V"<<" "<<v<<endl;
// for(int i=0;i<2*n+1;i++) cout<<seg.get(i,i+1)<<" ";
// cout<<endl;
seg.add(v,2*n+1,-2);
seg.add(2*v-1,2*n+1,-1);
if(seg.get(0,2*n+1)<0){
seg.add(v,2*n+1,2);
seg.add(2*v-1,2*n+1,1);
ok=false;
return;
}
if(c[v]==0) ps.insert(v);
c[v]++;
sumc++;
b[v]-=2;
if(b[v]<2){
nb.erase(v);
}
};
auto perase = [&](){
if(ps.size()==0) return;
auto itr=ps.begin();
ll v=(*itr);
b[v]+=2;
c[v]--;
sumc--;
seg.add(v,2*n+1,2);
seg.add(2*v-1,2*n+1,1);
if(b[v]>=2) nb.insert(v);
if(c[v]==0) ps.erase(v);
};
for(int _=0;_<q-1;_++){
ll x,d;
cin>>x>>d;
if(d==1){
/* for(auto e:b) cout<<e<<" ";
cout<<endl;
for(auto e:c) cout<<e<<" ";
cout<<endl;*/
badd(x);
/* for(auto e:b) cout<<e<<" ";
cout<<endl;
for(auto e:c) cout<<e<<" ";
cout<<endl; */
perase();
/* for(auto e:b) cout<<e<<" ";
cout<<endl;
for(auto e:c) cout<<e<<" ";
cout<<endl; */
ok=true;
while(ok){
// cout<<"ADD"<<" "<<nb.size()<<endl;
padd();
}
/* for(auto e:b) cout<<e<<" ";
cout<<endl;
for(auto e:c) cout<<e<<" ";
cout<<endl; */
}
else{
berase(x);
perase();
ok=true;
while(ok){
padd();
}
}
cout<<sumc<<endl;
}
}
Details
answer.code: In function ‘int main()’: answer.code:167:11: error: ‘b’ was not declared in this scope 167 | b[i]=a[i]-(a[i]/2)*2; | ^ answer.code:168:11: error: ‘c’ was not declared in this scope 168 | c[i]=a[i]/2; | ^ answer.code:172:11: error: ‘b’ was not declared in this scope 172 | b[i]=a[i]-2*k; | ^ answer.code:173:11: error: ‘c’ was not declared in this scope 173 | c[i]=k; | ^ answer.code:181:15: error: ‘c’ was not declared in this scope 181 | while(c[q]){ | ^ answer.code:186:27: error: ‘b’ was not declared in this scope 186 | ll use=min(c[q],b[p]); | ^