QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732902#9574. StripszsyRE 0ms3864kbC++203.6kb2024-11-10 16:22:032024-11-10 16:22:04

Judging History

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

  • [2024-11-10 16:22:04]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3864kb
  • [2024-11-10 16:22:03]
  • 提交

answer

//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,popK,sse4,abm")
#include <bits/stdc++.h>
#define int long long
#define db double
#define out(x) cerr << #x << '=' << (x) << '\n'
#define out2(x, y) cerr << #x << '=' << (x) << ',' << #y << '=' << (y) << '\n'
#define sz(x) (int)x.size()
#define fr first
#define sc second
#define INF 0x3f3f3f3f
#define y1 yyyyyy
#define lowbit(x) ((x) & -(x))
#define PI (db)acos(-1.0)
#define eb emplace_back
#define pb push_back
#define PII pair<i64,i64>
#define wrong std::string::npos
using i64 =long long;
using i128=__int128;

constexpr int N=1e5+5;
constexpr db eps=1e-8;
constexpr std::array<int, 8> dx{0, 1, 0, -1, 1, 1, -1, -1};
constexpr std::array<int, 8> dy{1, 0, -1, 0, 1, -1, 1, -1};
constexpr i64 mod = 998244353;

i64 fpow(i64 x, i64 r)
{
    i64 result = 1;
    while (r)
    {
        if (r & 1)result = result * x % mod;
        r >>= 1;
        x = x * x % mod;
    }
    return result;
}

i64 fpow1(i64 x, i64 r,i64 p)
{
    i64 result = 1;
    while (r)
    {
        if (r & 1)result = result * x % p;
        r >>= 1;
        x = x * x % p;
    }
    return result;
}


i64 fpow2(i64 x, i64 r)
{
    i64 result = 1;
    while (r)
    {
        if (r & 1)result = result * x;
        r >>= 1;
        x = x * x;
    }
    return result;
}
i64 gcd(i64 a,i64 b)
{
    return b?gcd(b,a%b):a;
}
void read(int &x){
    int f=1;x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    x*=f;
}

int a[N],b[N];
int n,m,k,w;
bool check(int mid) {
    int p=std::lower_bound(b,b+m,mid)-b;
    if(p>=m) return true;
    if(b[p]-k<mid) return false;
    return true;
}


void solve()
{
    std::cin>>n>>m>>k>>w;
    std::vector<int>t;
    for(int i=1;i<=n;i++) std::cin>>a[i];
    for(int i=0;i<m;i++) std::cin>>b[i];
    std::sort(a+1,a+1+n);
    std::sort(b,b+m);


    for(int i=1;i<n;i++)
    {
        if(!t.empty()&&t.back()+k-1>=a[i]) continue;
        int p=a[i]-k+1;
        p=std::max(1LL,p);
        int l=p,r=a[i],mid,tmp=0;
        r=std::min(r,w-k+1);
        if(sz(t)) l=std::max(l,t.back()+k);
        while (l<=r)
        {
            mid=l+r>>1;
            if(check(mid)) tmp=mid,l=mid+1;
            else r=mid-1;
        }
        if(tmp==0)
        {
            std::cout<<"-1\n";
            return;
        }
        t.pb(tmp);
    }
    if(t.back()+k-1<a[n])
    {
        if(a[n]>b[m-1])
        {
            int l=b[m-1]+1,r=a[n],tmp=0,mid;
            r=std::min(r,w-k+1);
            if(!t.empty()) l=std::max(l,t.back()+k);
            while (l<=r)
            {
                mid=l+r>>1;
                if(check(mid)) tmp=mid,l=mid+1;
                else r=mid-1;
            }
            t.pb(tmp);
        }
        else
        {
            int l=a[n]-k+1,r=a[n],mid,tmp=0;
            r=std::min(r,w-k+1);
            if(!t.empty()) l=std::max(l,t.back()+k);
            while (l<=r)
            {
                mid=l+r>>1;
                if(check(mid)) l=mid+1,tmp=mid;
                else r=mid-1;
            }
            t.pb(tmp);
        }
    }
    std::cout<<sz(t)<<'\n';
    for(int i=0;i<sz(t);i++) std::cout<<t[i]<<" \n"[i==sz(t)-1];
}

signed main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::cout<<std::fixed<<std::setprecision(10);

    int _=1;
    std::cin>>_;
    while(_--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

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:

4
2 7 10 14
-1
2
1 5
-1

result:

ok ok 4 cases (4 test cases)

Test #2:

score: -100
Runtime Error

input:

11000
3 8 2 53
32 3 33
35 19 38 20 1 30 10 6
7 10 1 42
3 14 4 36 28 40 22
17 20 12 41 27 7 1 19 13 9
6 6 13 78
55 76 53 32 54 58
62 45 21 4 7 61
8 7 3 68
9 26 54 31 22 3 38 65
34 16 58 47 52 29 53
5 8 4 33
33 5 30 6 15
27 12 9 28 19 2 13 10
6 1 2 48
8 12 48 1 41 31
40
7 6 7 61
20 19 30 52 49 17 40
3...

output:


result: