이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int M = 305;
const int mod = 1e9 + 7;
int n, k, a[N], res;
vector < int > dv;
void rec(int l, int r, int last) {
if(l >= r) return;
last++;
while(last < dv.size() && dv[last] < l) last++;
if(last == dv.size() || r <= dv[last]) return;
int lef = 0, righ = 0;
for(int i = l; i <= dv[last]; i++) {
lef += a[i];
}
for(int i = dv[last] + 1; i <= r; i++) {
righ += a[i];
}
res += lef * righ;
rec(l, dv[last], last);
rec(dv[last] + 1, r, last);
}
bool cmp(pii x, pii y) {
if(x.first > y.first) return 1;
if(x.first < y.first) return 0;
return x.second < y.second;
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//file("pieaters");
cin >> n >> k;
pii b[n + 1];
for(int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = {a[i], i};
}
sort(b + 1, b + n + 1, cmp);
for(int i = 1; i <= k; i++) {
dv.pb(b[i].second);
}
rec(1, n, -1);
cout << res << endl;
for(int i = 0; i < dv.size(); i++) {
cout << dv[i] << " ";
}
}
/*
7 3
4 1 3 4 0 2 3
*/
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'void rec(long long int, long long int, long long int)':
sequence.cpp:33:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while(last < dv.size() && dv[last] < l) last++;
| ~~~~~^~~~~~~~~~~
sequence.cpp:34:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if(last == dv.size() || r <= dv[last]) return;
| ~~~~~^~~~~~~~~~~~
sequence.cpp: At global scope:
sequence.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main() {
| ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:70:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < dv.size(); i++) {
| ~~^~~~~~~~~~~
# | 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... |