QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#177313#6883. Noblesse CodePPP#AC ✓832ms14424kbC++172.6kb2023-09-12 20:16:232023-09-12 20:16:23

Judging History

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

  • [2023-09-12 20:16:23]
  • 评测
  • 测评结果:AC
  • 用时:832ms
  • 内存:14424kb
  • [2023-09-12 20:16:23]
  • 提交

answer

#ifdef DEBUG
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const ll mod = 1000000007;
//const ll mod = 998244353;

#define X first
#define Y second

ll pew(ll a, ll b)
{
    ll res = 1;
    while (b>0)
    {
        if (b&1) res = res*a%mod;
        b >>= 1;
        a = a*a%mod;
    }
    return res;
}


map<pair<ll,ll>,ll> num;
ll TT = 0;
vector<pair<ll,ll>> Q[110000];

void solve()
{
    num.clear();
    TT = 0;
    ll n, q;
    cin >> n >> q;
    for (ll i=0;i<2*q;i++) Q[i].clear();
    vector<pair<ll,ll>> e(n);
    for (ll i=0;i<n;i++)
    {
        cin >> e[i].X >> e[i].Y;
    }
    for (ll i=0;i<q;i++)
    {
        ll x, y;
        cin >> x >> y;
        if (x<=y)
        {
            ll y2 = y%x;
            if (num.count({x,y2})==0) num[{x,y2}] = TT++;
            Q[num[{x,y2}]].push_back({y,i});
        }
        if (x>=y)
        {
            ll x2 = x%y;
            if (num.count({x2,y})==0) num[{x2,y}] = TT++;
            Q[num[{x2,y}]].push_back({x,i});
        }
    }
    vector<vector<ll>> D(TT);
    for (ll i=0;i<TT;i++)
    {
        sort(Q[i].begin(),Q[i].end());
        ll sz = Q[i].size();
        D[i].resize(sz+1);
    }
    for (ll i=0;i<n;i++)
    {
        ll a = e[i].X, b = e[i].Y;
        ll ans = 0;
        while (a>0 and b>0)
        {
            if (a>=b)
            {
                ll a2 = a%b;
                if (num.count({a2,b})!=0)
                {
                    ll p = num[{a2,b}];
                    pair<ll,ll> mn = {a+1,-1};
                    auto d = lower_bound(Q[p].begin(),Q[p].end(),mn)-Q[p].begin();
                    D[p][d]++;
                }
                a = a2;
                continue;
            }
            ll b2 = b%a;
            if (num.count({a,b2})!=0)
            {
                ll p = num[{a,b2}];
                pair<ll,ll> mn = {b+1,-1};
                auto d = lower_bound(Q[p].begin(),Q[p].end(),mn)-Q[p].begin();
                D[p][d]++;
            }
            b = b2;
        }
    }
    vector<ll> A(q);
    for (ll i=0;i<TT;i++)
    {
        ll sz = Q[i].size();
        ll W = 0;
        for (ll j=sz-1;j>=0;j--)
        {
            W += D[i][j+1];
            A[Q[i][j].Y] += W;
        }
    }
    for (ll i=0;i<q;i++) cout << A[i] << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#ifdef DEBUG
    //freopen("input.txt", "r", stdin);
//#endif
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 832ms
memory: 14424kb

input:

54
1000 1000
437949642385872929 860965504436928836
549207725345251140 807757620153191620
595135374173197122 535841165330085586
284216015123638122 991606310035186132
380255965462330700 718440783553992066
600098959546211922 568697564089219926
561489079983301188 490903512830837710
917947220777629314 45...

output:

1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 495000 lines