This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cmath>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
#pragma GCC optimize("Ofast")
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t;
cin>>t;
int largest = 500000;
for (int test = 0; test < t; test++) {
int n;
cin>>n;
unordered_set<int> kavlues;
for (int i = 2; i <= n; i++) {
kavlues.insert(i);
}
vector<int> pos(largest + 1, -1);
vector<int> pos_swap(largest + 1, -1);
pos[0] = 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin>>a[i];
}
for (int i = 0; i < n; i++) {
pos_swap.resize(largest + 1, -1);
pos_swap[a[i]] = i;
for (int s = 1; s <= largest; s++) {
if (a[i] + s > largest) {
break;
}
pos_swap[a[i] + s] = max(pos[a[i] + s], pos[s]);
}
swap(pos_swap, pos);
int sum = 0;
for (int j = i; j >= 0; j--) {
sum += a[j];
int amount = i - j + 1;
if (amount < 2) {
continue;
}
bool erase = false;
if (sum & 1) {
erase = true;
}
if (pos[sum >> 1] < j) {
erase = true;
}
if (erase && kavlues.find(amount) != kavlues.end()) {
kavlues.erase(amount);
}
}
}
vector<int> res;
for (auto& el : kavlues) {
res.push_back(el);
}
sort(res.begin(), res.end());
cout << res.size() << " ";
for (auto& el : res) {
cout << el << " ";
}
cout << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |