QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#62096#4496. Shinobu Loves Segment TreeqinjianbinAC ✓44ms3720kbC++4.8kb2022-11-17 10:01:422022-11-17 10:01:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-17 10:01:43]
  • 评测
  • 测评结果:AC
  • 用时:44ms
  • 内存:3720kb
  • [2022-11-17 10:01:42]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<ctime>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<functional>
using namespace std;
//STL库常用(vector, map, set, pair)
#define pii pair<int,int>
#define pdd pair<double,double>
#define F first
#define S second
//常量
#define PI (acos(-1.0))
#define INF 0x3f3f3f3f
//必加
#ifdef TanJI
#include<cassert>
#define dbg(...) do {cerr << #__VA_ARGS__ << " -> "; err(__VA_ARGS__); } while(0)
void err() {cerr << endl;}
template<template<typename...> class T, typename t, typename... A> void err(T<t> a, A... x) {for (auto v: a) cerr << v << ' '; cerr << ", "; err(x...);}
template<typename T, typename... A> void err(T a, A... x) {cerr << a << ' '; err(x...);}
template<typename T> void err(T *a, int len) {for (int i = 0; i < len; i++) cerr << a[i] << ' '; err();}
#else 
#define dbg(...)
#define assert(...)
#endif
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
// 快读快输
template<typename T> inline T read() {T x=0; bool f=0; char c=getchar();while(!isdigit(c)){if(c =='-')f= 1; c=getchar();}while(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=getchar();}return f?~x+1:x;}
template<typename T> inline void print(T k){ int num = 0,ch[20]; if(k == 0){ putchar('0'); return ; } (k<0)&&(putchar('-'),k = -k); while(k>0) ch[++num] = k%10, k /= 10; while(num) putchar(ch[num--]+48); }
//图论
const int GRAPHN = 1, GRAPHM = 1;
int h[GRAPHN], e[GRAPHM], ne[GRAPHM], wei[GRAPHM], idx;
void AddEdge(int a, int b) {e[idx] = b, ne[idx] = h[a], h[a] = idx++;}
void AddEdge(int a, int b, int c) {e[idx] = b, ne[idx] = h[a], wei[idx] = c, h[a] = idx++;}
void AddEdge(int h[], int a, int b) {e[idx] = b, ne[idx] = h[a], h[a] = idx++;}
void AddEdge(int h[], int a, int b, int c) {e[idx] = b, ne[idx] = h[a], wei[idx] = c, h[a] = idx++;}
// 数学公式
template<typename T> inline T gcd(T a, T b){ return b==0 ? a : gcd(b,a%b); }
template<typename T> inline T lowbit(T x){ return x&(-x); }
template<typename T> inline bool mishu(T x){ return x>0?(x&(x-1))==0:false; }
template<typename T1,typename T2, typename T3> inline ll q_mul(T1 a,T2 b,T3 p){ ll w = 0; while(b){ if(b&1) w = (w+a)%p; b>>=1; a = (a+a)%p; } return w; }
template<typename T,typename T2> inline ll f_mul(T a,T b,T2 p){ return (a*b - (ll)((long double)a/p*b)*p+p)%p; }
template<typename T1,typename T2, typename T3> inline ll q_pow(T1 a,T2 b,T3 p){ ll w = 1; while(b){ if(b&1) w = (w*a)%p; b>>=1; a = (a*a)%p;} return w; }
template<typename T1,typename T2, typename T3> inline ll s_pow(T1 a,T2 b,T3 p){ ll w = 1; while(b){ if(b&1) w = q_mul(w,a,p); b>>=1; a = q_mul(a,a,p);} return w; }
template<typename T> inline ll ex_gcd(T a, T b, T& x, T& y){ if(b == 0){ x = 1, y = 0; return (ll)a; } ll r = ex_gcd(b,a%b,y,x); y -= a/b*x; return r;/*gcd*/ }
template<typename T1,typename T2> inline ll com(T1 m, T2 n) { int k = 1;ll ans = 1; while(k <= n){ ans=((m-k+1)*ans)/k;k++;} return ans; }
template<typename T> inline bool isprime(T n){ if(n <= 3) return n>1; if(n%6 != 1 && n%6 != 5) return 0; T n_s = floor(sqrt((db)(n))); for(int i = 5; i <= n_s; i += 6){ if(n%i == 0 || n%(i+2) == 0) return 0; } return 1; }
/* ----------------------------------------------------------------------------------------------------------------------------------------------------------------- */

const int MAXN = 1e5 + 10;

int T;
ll n, x;

ll solve() {
    scanf("%lld%lld", &n, &x);
    ll lim = 1;
    ll cnt = 0;
    if (x == 1) {
        lim = 1;
    }
    else {
        lim = 2;
        ll xx = x >> 1;
        cnt++;
        while (xx != 1) {
            if (xx & 1) lim = lim * 2;
            else lim = lim * 2 - 1;
            xx >>= 1;
            cnt++;
        }
    }
    cnt = 1 << cnt;
    ll siz = n - lim + 1;
    if (siz <= 0) return 0;
    ll ans = 0, ned1 = 0;
    if (x & 1) 
        ned1 = cnt;
    else ned1 = cnt >> 1;
    dbg(siz, ned1);
    if (siz < ned1) return siz;
    else {
        ans = ned1;
        siz -= ned1;
        ll num = siz / cnt;
        ans += (num + 3) * num * cnt / 2;
        siz = siz % cnt;
        dbg(num, cnt, siz, ans);
        ans += siz * (num + 2);
        return ans;
    }    
}

int main() {
#ifdef TanJI
    clock_t c1 = clock();
    freopen("D:\\Cpp\\1.in", "r", stdin);
    freopen("D:\\Cpp\\1.out", "w", stdout);
#endif
//--------------------------------------------
    scanf("%d", &T);
    while (T--) {
        printf("%lld\n", solve());
    }
//--------------------------------------------    
#ifdef TanJI
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 44ms
memory: 3720kb

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