QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661958#8142. Elevatorcc1314WA 49ms19976kbC++172.1kb2024-10-20 19:27:372024-10-20 19:27:38

Judging History

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

  • [2024-10-20 19:27:38]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:19976kb
  • [2024-10-20 19:27:37]
  • 提交

answer

//#pragma GCC optimize(1)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")

#include<bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define int long long
#define ll __int128
#define double long double
#define lowbit(x) (x&(-x))
#define log(x) (31^__builtin_clz(x))
#define endl '\n'

typedef pair<int,int>PII;
typedef pair<double,double>PDD;
typedef tuple<double,double,double>TDDD;
typedef tuple<int,int,int>TIII;

const int N = 5e5+10;
const int mod = 1e9+7 , P = 131;
const double PI = acos(-1);
const double eps = 1e-8;

mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());//随机数

int read(){
    char c=0;
    int res=0;
    int f=1;
    while(!(c>='0'&&c<='9')){
        if(c=='-'){
            f=-f;
        }
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        res=(res<<3)+(res<<1)+c-'0';
        c=getchar();
    }
    return res*f;
}

void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(char(x%10+'0'));
}

int n,m;
int w[N];
struct E{
    int val,id;
    bool operator<(const E& t)const{
        return val<t.val;
    }
}e[N];
int tt;
int ans[N],tr[N];

void add(int x,int c){
    for(int i=x;i<N;i+=lowbit(i))tr[i]+=c;
}

int query(int x){
    int res=0;
    for(int i=x;i;i-=lowbit(i))res+=tr[i];
    return res;
}

void solve(){
    cin>>n>>m;

    map<int,int>S;

    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        e[i]={x,i};
    }

    sort(e+1,e+1+n);

    int sum=0;
    for(int i=1;i<=n;i++){
        int j=e[i].id;
        int t=query(j);
        add(j,1);
        t+=e[i].val*(i-1)-sum;
        if(t>=m-1)t=-1;
        ans[j]=t;
        sum+=e[i].val;
    }

    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }

}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int T;
    T=1;
    while(T--)solve();

#ifdef GREENQWQ
    cerr<<fixed<<setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9816kb

input:

6 20
3 8 12 6 9 9

output:

0
8
-1
4
13
14

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 49ms
memory: 19976kb

input:

500000 1000000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
16
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
32
32
32
32
32
32
32
32
32
32
32
32
32
32
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
16
32
32
32
32
32
32
32
32
32
32
32
32
32
32
31
32
32
32
32
32
32
32
32
32
32
32
32
32...

result:

wrong answer 2nd lines differ - expected: '1', found: '0'