QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#827894#4496. Shinobu Loves Segment TreeeastcloudAC ✓232ms3672kbC++231.6kb2024-12-23 11:05:562024-12-23 11:06:00

Judging History

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

  • [2024-12-23 11:06:00]
  • 评测
  • 测评结果:AC
  • 用时:232ms
  • 内存:3672kb
  • [2024-12-23 11:05:56]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define eb emplace_back
#define IL inline
#define For(i,j,k) for(ll i=(j);i<=(k);i++)
#define Fol(i,k,j) for(ll i=(k);i>=(j);i--)

using namespace std;

ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(ll x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

void debug(auto &&...x){
    ((cerr<<x<<' '),...);
    cerr<<'\n';
}

ll get(ll x,ll val){
    while(x!=1){    
        if(val==1)val=2*val;
        else if(x&1)val=2*val;
        else val=2*val-1;x>>=1;
    }
    return val;
}

void solve(){
    ll n=read(),x=read();
    ll t1=get(x,1),t2=get(x,2),t3=get(x,3);
    debug(n,x,t1,t2,t3,get(x,4));
    if(n<t1)write(0);
    else if(n<t2)write(n-t1+1);
    else if(n<t3)write(t2-t1+2*(n-t2+1));
    else{
        ll res=0;res+=(t2-t1);
        ll d=(n-t2+1)/(t3-t2),m=t2+d*(t3-t2),k=2+d;
        res=res+(n-m+1)*k+(t3-t2)*(2+(2+d-1))*d/2;
        write(res);
    }
    putchar('\n');
}

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    #endif
 
    ll T=read();while(T--)solve();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 232ms
memory: 3672kb

input:

100000
249 707
360 1429
151 380
118 103
221 711
88 79
471 1668
222 377
481 676
483 921
326 558
347 1151
104 220
91 97
258 250
446 122
368 1335
242 335
395 470
180 669
99 222
342 979
345 431
119 97
283 781
325 643
488 1413
285 868
205 723
118 115
397 526
432 1557
197 761
145 287
304 270
331 243
98 36...

output:

0
0
0
61
0
28
0
64
151
176
0
0
11
58
230
1585
0
0
192
0
0
0
100
108
0
0
0
0
0
70
0
0
0
0
64
328
0
808
390
0
0
0
35
0
63
128
405
0
0
52
0
0
146
0
48
662
0
0
0
0
72
6757
0
15
63
150
30
6
66
0
0
236
0
459
100
0
63
0
0
105
0
81
34
0
0
208
0
0
2484
0
63
71
198
89
172
83
19
160
0
237
0
0
0
28
423
32
0
220...

result:

ok 100000 lines