QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729267#9574. Stripsucup-team4801#TL 0ms0kbC++142.2kb2024-11-09 16:48:342024-11-09 16:48:40

Judging History

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

  • [2024-11-09 16:48:40]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-09 16:48:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5;

int f[N];
int a[N], b[N];
int K;
vector<int> ans;


bool solve(int l, int r, int L, int R){
    f[l - 1] = L;
    for(int i = l; i <= r; i ++){
        int u = upper_bound(a + l, a + i + 1, a[i] - K) - a;
        f[i] = max(f[u - 1] + K - 1, a[i]);
    }

    if(f[r] > R)return 0;

    int t = r;
    while(1){
        int u = upper_bound(a + l, a + t + 1, a[t] - K) - a;
        int pos = f[t] - K + 1;
        ans.push_back(pos);
        t = u - 1;
        if(t < l)break;
    }
    
    return 1;

    // vector<int> res;
    // while(1){
    //     int u = lower_bound(a + t + 1, a + r + 1, a[t] + K) - a;
    //     int pos = max(lst, a[u - 1] - K + 1);
    //     res.push_back(pos); lst = pos + K;
    //     if(lst > R + 1)break;
    //     t = u;
    //     if(t > r)break;
    // }

    // if(t > r){
    //     for(int u : res)ans.push_back(u);
    //     return 1;
    // }

    // res.clear();
    // t = r;
    // lst = R;
    // while(1){
    //     int u = upper_bound(a + l, a + t + 1, a[t] - K) - a;
    //     int pos = min(lst - K + 1, a[u]);
    //     res.push_back(pos); lst = pos - 1;
    //     if(lst < L - 1)break;
    //     t = u - 1;
    //     if(t < l)break;
    // }

    // if(t < l){
    //     for(int u : res)ans.push_back(u);
    //     return 1;
    // 

    // return 0;
}

void solve(){
    ans.clear();
    int n, m, w;
    scanf("%d%d%d%d", &n, &m, &K, &w);

    for(int i = 1; i <= n; i ++)scanf("%d", &a[i]);
    for(int i = 1; i <= m; i ++)scanf("%d", &b[i]);
    b[++ m] = 0; b[++ m] = w + 1;

    sort(a + 1, a + n + 1);
    sort(b + 1, b + m + 1);

    int j = 1;
    for(int i = 1; i < m; i ++){
        int l = j;
        while(j <= n && a[j] < b[i + 1])j ++;
        if(!solve(l, j - 1, b[i] + 1, b[i + 1] - 1)){
            puts("-1");
            return ;
        }
    }

    printf("%d\n", (int)ans.size());

    for(int u : ans){
        printf("%d ", u);
    }
    puts("");
}

int main(){
    freopen("in", "r", stdin);

    int T;
    scanf("%d", &T);

    while(T --)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

4
5 2 3 16
7 11 2 9 14
13 5
3 2 4 11
6 10 2
1 11
2 1 2 6
1 5
3
2 1 2 6
1 5
2

output:


result: