이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#ifndef EVAL
#include "grader.cpp"
#endif // EVAL
#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
lol dis[1001001],mx[1001001],q[1001001];
struct node{
lol ans,pref,suff,sz;
}der[1001001];
node merg(node a,node b){
node ans ;
ans.pref = a.pref;
ans.suff = b.suff;
ans.ans = max(a.suff+b.pref,max(a.ans,b.ans));
if (b.sz == b.suff){
ans.suff += a.suff;
}
if (a.sz == a.pref){
ans.pref += b.pref;
}
ans.sz = a.sz+b.sz;
ret ans;
}
void build(int v,int l,int r){
if (l == r){
der[v].pref = (q[l] == 1);
der[v].suff = (q[l] == 1);
der[v].ans = (q[l] == 1);
der[v].sz = 1;
}
else {
int m = l+r>>1;
build(v<<1,l,m);
build((v<<1)+1,m+1,r);
der[v] = merg(der[v<<1],der[(v<<1)+1]);
}
}
node getLR(int v,int l,int r,int ql,int qr){
node ans;
ans.ans = 0;
ans.pref = 0;
ans.suff = 0;
if (l > qr || r < ql)ret ans;
if (ql <= l && r <= qr)ret der[v];
else {
int m = l+r>>1;
ans = merg(getLR(v<<1,l,m,ql,qr),getLR((v<<1)+1,m+1,r,ql,qr));
ret ans;
}
}
vector<lol> minimum_costs(vector<int> H, vector<int> L,vector<int> R) {
int i,j,k,n = H.size(),Q = L.size();
vector<lol> C(Q);
for (i=0;i<n;++i)q[i] = H[i];
build(1,0,n-1);
for (i=0;i<Q;++i){
node x = getLR(1,0,n-1,L[i],R[i]);
lol s = R[i]-L[i]+1;
C[i] = (s-x.ans)*2;
C[i] += x.ans;
}
ret C;
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'void build(int, int, int)':
meetings.cpp:57:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
57 | int m = l+r>>1;
| ~^~
meetings.cpp: In function 'node getLR(int, int, int, int, int)':
meetings.cpp:72:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
72 | int m = l+r>>1;
| ~^~
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:80:11: warning: unused variable 'j' [-Wunused-variable]
80 | int i,j,k,n = H.size(),Q = L.size();
| ^
meetings.cpp:80:13: warning: unused variable 'k' [-Wunused-variable]
80 | int i,j,k,n = H.size(),Q = L.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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |