Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int mod = 1000007;
- int main() {
- int n,t;
- cin >> n;
- int cs = 350;
- int size = (n/cs)+1;
- int arr[size][350];
- double arr_sum[size];
- for(int i = 0; i < size; i++)
- {
- for(int j = 0; j < 350; j++)
- {
- arr[i][j] = 0;
- }
- arr_sum[i] = 1100000000;
- }
- int last = 0;
- for(int j = 0; j < 350; j++)
- {
- if(arr[size-1][j] != 0)
- {
- last++;
- }
- }
- for(int i = 0; i < n; i++)
- {
- cin >> arr[i/350][i%350];
- arr_sum[i/350]=min((double)arr[i/350][i%350]/2, arr_sum[i/350]);
- }
- for(int i = 0; i < n; i++) {
- double temp = arr[i / 350][i % 350] / 2;
- int failedblockindex = -1;
- for (int j = (i / 350) + 1; j < size; j++) {
- if (arr_sum[j] < temp) {
- failedblockindex = j;
- break;
- } else {
- temp = max((double) arr_sum[j], temp);
- }
- }
- for (int j = 0; j < i / 350; j++) {
- if (arr_sum[j] < temp) {
- failedblockindex = j;
- break;
- } else {
- temp = max((double) arr_sum[j], temp);
- }
- }
- int index = -1;
- for (int j = 0; j < 350; j++) {
- if (arr[failedblockindex][index] < temp && arr[failedblockindex][index] != 0) {
- index = j;
- break;
- }
- }
- if (failedblockindex == -1) {
- double temp3 = (double) arr[i / 350][i % 350] / 2;
- for (int j = i % 350; j < 350; j++) {
- if (arr[i / 350][j] < temp3 && arr[i / 350][j] != 0) {
- index = j;
- break;
- } else temp3 = max(temp3, (double) arr[i / 350][j] / 2);
- }
- if (index != -1)
- cout << (index - i) << " ";
- else {
- for (int j = 0; j < i % 350; j++) {
- if (arr[i / 350][j] < temp && arr[i / 350][j] != 0) {
- index = j;
- break;
- } else temp = max(temp, (double) arr[i / 350][j] / 2);
- }
- if (index == -1) cout << -1 << " ";
- else {
- cout << n - (i%350-index) << " ";
- // else cout << n - (350 - index - 1) << " "; //MAYBE CHECK SIZE =1
- }
- }
- } else if (failedblockindex > i / 350 && failedblockindex != -1) {
- cout << (350 - i + 1 + ((failedblockindex - 1 - (i / 350)) * 350) + 350 - index) << " ";
- } else if(failedblockindex != -1 && failedblockindex < i / 350){
- cout << (350 - i + 1 + ((size - 1 - (i / 350)) * 350) + last + index + (failedblockindex - 1) * 350) << " ";
- }
- else
- {
- cout << -1 << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement