Submission #952974

#TimeUsernameProblemLanguageResultExecution timeMemory
952974SacharlemagneDiversity (CEOI21_diversity)C++17
4 / 100
7015 ms604 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { //ios_base::sync_with_stdio(false); cin.tie(nullptr); int n,q; cin >> n >> q; vector<int> vv(n); for (int i = 0; i<n; ++i) cin >> vv[i]; while (q--) { long long fin = 4e18; int L, R; cin >> L >> R; --L; --R; vector<int> v(R-L+1); for (int i = 0; i<R-L+1; ++i) v[i] = vv[i+L]; do { ll ans = 0; map<ll,ll> last; for (ll i = 0; i<v.size(); ++i) { int bef = last[v[i]]; ans += (i-bef+1)*(v.size()-i); last[v[i]] = i+1; } fin = min(fin, ans); } while (next_permutation(v.begin(), v.end())); cout << fin << '\n'; } return 0; } /* * */

Compilation message (stderr)

diversity.cpp: In function 'int main()':
diversity.cpp:18:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |    for (ll i = 0; i<v.size(); ++i) {
      |                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...