답안 #700157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700157 2023-02-18T18:07:23 Z PedroBigMan 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
#include "candies.h"
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000000000LL
#define EPS 0.00000001
#define pi 3.14159
#define VV(vvvv,NNNN,xxxx); REP(i,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007LL;

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

class ST
{	
    public:
    ll N;
    
    class SV //seg value
    {
        public:
        ll a;
        SV() {a=-INF;}
        SV(ll x) {a=x;}
        
        SV operator & (SV X) {SV ANS(max(a,X.a)); return ANS;}
    };
      
    class LV //lazy value
    {
        public:
        pl ext; ll s;
        LV() {ext={-INF,INF}; s=0LL;}
        LV(pl ex, ll sss) {ext=ex; s=sss;}
        
        LV operator & (LV X) 
		{
			if(max(ext.ff,X.ext.ff+s)<=min(ext.ss,X.ext.ss+s)) {LV ANS({max(ext.ff,X.ext.ff+s),min(ext.ss,X.ext.ss+s)},s+X.s); return ANS;}
			else if(ext.ss<X.ext.ff+s) {LV ANS({ext.ss,ext.ss},0LL); return ANS;}
			else {LV ANS({ext.ff,ext.ff},0LL); return ANS;}
		}
    };
    
    SV upval(ll c) //how lazy values modify a seg value inside a node, c=current node
    {
        SV ANS(max(lazy[c].ext.ff,min(lazy[c].ext.ss,p[c].a+lazy[c].s)));
        return ANS;
    }
    
    SV neuts; LV neutl;
    
    vector<SV> p;
    vector<LV> lazy;
    vector<pl> range;
    
    ST() {N=0LL;}
    ST(vector<ll> arr)
    {
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,2*N) {range.pb(mp(0LL,0LL));}
        REP(i,0,N) {p.pb(neuts);}
        REP(i,0,arr.size()) {SV X(arr[i]); p.pb(X); range[i+N]=mp(i,i);}
        REP(i,arr.size(),N) {p.pb(neuts); range[i+N]=mp(i,i);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=p[2*cur]&p[2*cur+1];
            range[cur]=mp(range[2*cur].ff,range[2*cur+1].ss);
            cur--;
        }
        REP(i,0,2*N) {lazy.pb(neutl);}
    }
    
    void prop(ll c) //how lazy values propagate
    {
        lazy[2*c]=lazy[c]&lazy[2*c]; lazy[2*c+1]=lazy[c]&lazy[2*c+1];
        lazy[c]=neutl;
    }
    
    SV query(ll a,ll b, ll c=1LL) //range [a,b], current node. initially: query(a,b)
    {
        ll x=range[c].ff; ll y=range[c].ss;
        if(y<a || x>b) {return neuts;}
        if(x>=a && y<=b) {return upval(c);}
        prop(c);
		p[c]=upval(2*c)&upval(2*c+1);
        SV ans = query(a,b,2*c)&query(a,b,2*c+1);
        return ans;
    }
    
    void update(LV s, ll a, ll b, ll c=1LL) //update LV, range [a,b], current node, current range. initially: update(s,a,b)
    {
        ll x=range[c].ff; ll y=range[c].ss;
        if(y<a || x>b) {return ;}
        if(x>=a && y<=b) 
        {
            lazy[c]=s&lazy[c]; 
            return;
        }
		prop(c);
        update(s,a,b,2*c); update(s,a,b,2*c+1);
        p[c]=upval(2*c)&upval(2*c+1);
    }
};

vector<int> distribute_candies(vector<int> cc, vector<int> lll, vector<int> rrr, vector<int> vv) 
{
   	ll N,Q; vector<ll> ,L,R,V;
	N=cc.size(); 
	Q=lll.size(); REP(i,0,Q) {L.pb((ll) lll[i]); R.pb((ll) rrr[i]); V.pb((ll) vv[i]);} 
	vector<ll> xx; VV(xx,N,0LL); ST S(xx); ll C=cc[0];
	REP(i,0,Q)
	{
		S.update(({0,C},V[i]),L[i],R[i]);
	}
	vector<int> ans; REP(i,0,N) {ans.pb(S.query(i,i).a);}
	return ans;
}

Compilation message

candies.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
candies.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      | 
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:143:24: error: expected unqualified-id before ',' token
  143 |     ll N,Q; vector<ll> ,L,R,V;
      |                        ^
candies.cpp:149:14: warning: left operand of comma operator has no effect [-Wunused-value]
  149 |   S.update(({0,C},V[i]),L[i],R[i]);
      |              ^
candies.cpp:149:17: error: expected ';' before '}' token
  149 |   S.update(({0,C},V[i]),L[i],R[i]);
      |                 ^
      |                 ;
candies.cpp:149:18: error: expected ')' before ',' token
  149 |   S.update(({0,C},V[i]),L[i],R[i]);
      |            ~     ^
      |                  )
candies.cpp:149:35: error: expected ')' before ';' token
  149 |   S.update(({0,C},V[i]),L[i],R[i]);
      |           ~                       ^
      |                                   )