QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643406#7904. Rainbow SubarrayLeft0807Compile Error//C++202.3kb2024-10-15 21:02:312024-10-15 21:02:32

Judging History

你现在查看的是最新测评结果

  • [2024-10-15 21:02:32]
  • 评测
  • [2024-10-15 21:02:31]
  • 提交

answer

#define int long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;

int INF = 1e18; 
const int MOD = 998244353;
const int N = 5e5 + 10;
const int LOG = 20;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int BIT[N], cBIT[N], a[N];
vector<int> nums;
int n, k;


void add(int x, int val, int c){
    for(int i = x; i <= nums.size(); i += i&-i){
        BIT[i] += val, cBIT[i] += c;
    }
}

int qry(int x){
    int res = 0;
    for(int i = x; i > 0; i -= i&-i) res += BIT[i];
    return res;
}
    
int cqry(int x){
    int res = 0;
    for(int i = x; i > 0; i -= i&-i) res += cBIT[i];
    return res;
}


int find(int x){
    int res = lower_bound(all(nums), x) - nums.begin();
    if(nums[res] == x) res++;
    return res;
}

int cal(int l, int r){
    int res = INF;
    int tot = qry(nums.size());
    int avg = tot / (r - l + 1);

    for(int j = -1; j <= 1; j++){
        avg += j;

        int l_c = cqry(find(avg));
        int r_c = (r - l + 1) - l_c;
        int l_sum = qry(find(avg));
        int r_sum = tot - l_sum;
            
        res = min(res, l_c * avg - l_sum + r_sum - r_c * avg);

        avg -= j;
    }

    return res;
}

bool DEBUG = false;

void solve(){
    cin >> n >> k;    
    nums.clear();
    nums.push_back(0);

    if(DEBUG) cout << n << ' ' << k << '\n';

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(DEBUG) cout << a[i] << ' ';
        a[i] -= i;
        if(a[i] < 0) a[i] = -a[i];
        nums.push_back(a[i]);
    }

    if(DEBUG) cout << '\n';

    sort(all(nums));
    nums.erase(unique(all(nums)), nums.end());

    int l = 1, r = 1;
    int ans = 0;

    while(r <= n){
        add(find(a[r]), a[r], 1);

        while(l < r && cal(l, r) > k){
            add(find(a[l]), -a[l], -1);
            l++;
        }

        ans = max(ans, r - l + 1);
        r++;
    }

    while(l <= n){
        add(find(a[l]), -a[l], -1);
        l++;
    }

    cout << ans << '\n';
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int tt;
    cin >> tt;

    if(tt == 11102) DEBUG = 1;

    while(tt--){
        solve();
    }
}

详细

answer.code:13:1: error: ‘mt19937’ does not name a type
   13 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      | ^~~~~~~
answer.code:16:1: error: ‘vector’ does not name a type
   16 | vector<int> nums;
      | ^~~~~~
answer.code: In function ‘void add(long long int, long long int, long long int)’:
answer.code:21:25: error: ‘nums’ was not declared in this scope
   21 |     for(int i = x; i <= nums.size(); i += i&-i){
      |                         ^~~~
answer.code: In function ‘long long int find(long long int)’:
answer.code:40:31: error: ‘nums’ was not declared in this scope
   40 |     int res = lower_bound(all(nums), x) - nums.begin();
      |                               ^~~~
answer.code:3:16: note: in definition of macro ‘all’
    3 | #define all(a) a.begin(), a.end()
      |                ^
answer.code:40:15: error: ‘lower_bound’ was not declared in this scope
   40 |     int res = lower_bound(all(nums), x) - nums.begin();
      |               ^~~~~~~~~~~
answer.code: In function ‘long long int cal(long long int, long long int)’:
answer.code:47:19: error: ‘nums’ was not declared in this scope
   47 |     int tot = qry(nums.size());
      |                   ^~~~
answer.code:58:15: error: ‘min’ was not declared in this scope
   58 |         res = min(res, l_c * avg - l_sum + r_sum - r_c * avg);
      |               ^~~
answer.code: In function ‘void solve()’:
answer.code:69:5: error: ‘cin’ was not declared in this scope
   69 |     cin >> n >> k;
      |     ^~~
answer.code:1:1: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
  +++ |+#include <iostream>
    1 | #define int long long
answer.code:70:5: error: ‘nums’ was not declared in this scope
   70 |     nums.clear();
      |     ^~~~
answer.code:73:15: error: ‘cout’ was not declared in this scope
   73 |     if(DEBUG) cout << n << ' ' << k << '\n';
      |               ^~~~
answer.code:73:15: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
answer.code:77:19: error: ‘cout’ was not declared in this scope
   77 |         if(DEBUG) cout << a[i] << ' ';
      |                   ^~~~
answer.code:77:19: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
answer.code:83:15: error: ‘cout’ was not declared in this scope
   83 |     if(DEBUG) cout << '\n';
      |               ^~~~
answer.code:83:15: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
answer.code:85:5: error: ‘sort’ was not declared in this scope; did you mean ‘short’?
   85 |     sort(all(nums));
      |     ^~~~
      |     short
answer.code:86:16: error: ‘unique’ was not declared in this scope
   86 |     nums.erase(unique(all(nums)), nums.end());
      |                ^~~~~~
answer.code:99:15: error: ‘max’ was not declared in this scope
   99 |         ans = max(ans, r - l + 1);
      |               ^~~
answer.code:108:5: error: ‘cout’ was not declared in this scope
  108 |     cout << ans << '\n';
      |     ^~~~
answer.code:108:5: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
answer.code: At global scope:
answer.code:111:1: error: ‘int32_t’ does not name a type
  111 | int32_t main(){
      | ^~~~~~~
answer.code:1:1: note: ‘int32_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
  +++ |+#include <cstdint>
    1 | #define int long long