이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define len(x) (int)x.size()
#define ull unsigned long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define int long long
#define double long double
#define pii pair<int,int>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ll inf = 1e9;
int n,k,a[N],p[N],ans;
vector <pii> v,vv;
vector <pii> q;
main(){
// freopen("txt.in", "r", stdin);
// freopen("txt.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i=1;i<=n;i++){
cin >> a[i];
p[i] = p[i-1] + a[i];
}
v.pb({1,n});
while (!v.empty()){
for (auto it : v){
int l = it.F;
int r = it.S;
int mid = (p[it.S] - p[it.F-1]) / 2;
while(l<=r){
int md = (l + r) / 2;
int x = p[md] - p[it.F-1];
if (x <= mid){
l = md + 1;
}
else{
r = md - 1;
}
}
if (r>=it.F && r<=it.S){
q.pb({(p[it.S] - p[r]) * (p[r] - p[it.F-1]), r});
if (r > it.F)vv.pb({it.F,r});
if (r+1 < it.S)vv.pb({r+1,it.S});
}
}
v.clear();
if (!vv.empty())v = vv;
vv.clear();
}
sort(q.begin(),q.end(),greater<pii>());
for (int i=0;i<min(k,len(q));i++){
ans+=q[i].F;
}
cout << ans << '\n';
for (int i=0;i<min(k,len(q));i++){
cout << q[i].S << ' ';
}
}
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)
//a/b%mod = a*(b^(m-2)%mod)
//(a>>x)&1 == 0
//a^b = (a+b)-2(a&b)
//srand(time(0))-always changing
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
32 | main(){
| ^~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |