提出 #56304073


ソースコード 拡げる

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define REP_(I,N) for (int I=0,END=(N);I<END;I++)
#define rREP_(I,N) for (int I=(N)-1;I>=0;I--)
#define rep_(I,S,N) for (int I=(S),END=(N);I<END;I++)
#define rrep_(I,S,N) for (int I=(N)-1,START=(S);I>=START;I--)
#define FOR_(I,S,N) for (int I=(S),END=(N);I<=END;I++)
#define rFOR_(I,S,N) for (int I=(N),START=(S);I>=START;I--)

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL maxn=1e6+7;
const double pi=acos(-1.0);
const double eps=1e-10;
template<typename T>inline void pr2(T x,int k=64) {REP_(i,k) printf("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
inline ll fastgcd(ll a, ll b) {  // __gcd()
    if (!b||!a) return a|b;
    ll az=__builtin_ctzll(a),bz=__builtin_ctzll(b),z=min(az,bz),diff; b>>=bz;
    while (a) {
        a>>=az, diff=b-a, az=__builtin_ctzll(diff);
        (b>a)&&(b=a), a=abs(diff);
    }
    return b<<z;
}
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}
typedef array<int,5> ar5;
typedef array<int,4> ar4;
typedef array<int,3> ar3;
std::mt19937 rng(time(0));
std::mt19937_64 rng64(time(0));
vector<pii> direction4 = {{-1,0},{0,-1},{0,1},{1,0}};
vector<pii> direction8 = {{-1,-1},{-1,0},{1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

// const int mod = 1e9+7;
const int mod=998244353;
struct mint {
    long long x;
    mint():x(0) {}
    mint(long long x):x((x%mod+mod)%mod) {}
    // mint(long long x):x(x){}
    mint &fix() { x = (x%mod+mod)%mod; return *this; }
    mint operator-() const { return mint(0) - *this; }
    mint operator~() const { return mint(1) / *this; }
    mint &operator+=(const mint &a) { if ((x+=a.x)>=mod) x-=mod; return *this; }
    mint &operator-=(const mint &a) { if ((x+=mod-a.x)>=mod) x-=mod; return *this; }
    mint &operator*=(const mint &a) { (x*=a.x)%=mod; return *this; }
    mint &operator/=(const mint &a) { (x*=a.pow(mod-2).x)%=mod; return *this; }
    mint operator+(const mint &a)const { return mint(*this) += a; }
    mint operator-(const mint &a)const { return mint(*this) -= a; }
    mint operator*(const mint &a)const { return mint(*this) *= a; }
    mint operator/(const mint &a)const { return mint(*this) /= a; }
    mint pow(long long t) const {
        mint ret=1,cur=x;
        for (; t; t>>=1ll,cur=cur*cur)
            if (t&1) ret=ret*cur;
        return ret;
    }
    bool operator<(const mint &a)const { return x < a.x; }
    bool operator==(const mint &a)const { return x == a.x; }
};
istream & operator>>(istream &o,mint &a) { o>>a.x; a=a.fix(); return o; }
ostream & operator<<(ostream &o,const mint &a) { o<<a.x; return o; }

int solve() {
    int n;
    scanf("%d",&n);
    vector<vector<array<int,2>>> items(n+1);
    int m;
    scanf("%d",&m);
    vector<int> mark(n+1);
    vector<int> T(m+1),P(m+1);
    FOR_(i,1,m) {
        int t,p;
        scanf("%d%d",&t,&p);
        T[i]=t; P[i]=p;
        items[p].push_back({t,mark[p]});
        mark[p]^=1;
    }

    int q;
    scanf("%d",&q);
    vector<int> result(q+1);
    vector<vector<pair<int,int>>> queries(n+1);
    int B=500;
    // int B=0;
    FOR_(i,1,q) {
        int a,b;
        scanf("%d%d",&a,&b);
        if (items[a].size()<=B&&items[b].size()<=B) {
            int x=0,y=0,t=0,res=0;
            while (x<items[a].size()&&y<items[b].size()) {
                int nxt=min(items[a][x][0],items[b][y][0]);
                if (items[a][x][1]==1&&items[b][y][1]==1) res+=nxt-t+1;
                t=nxt+1;
                while (x<items[a].size()&&items[a][x][0]<=nxt) x++;
                while (y<items[b].size()&&items[b][y][0]<=nxt) y++;
            }
            // printf("%d\n",res);
            result[i]=res;
        } else {
            if (items[a].size()>=B) queries[a].push_back({b,i});
            else queries[b].push_back({a,i});
        }
    }
    vector<int> prefsum(m+1),cur(n+1);
    FOR_(t,1,n) if (queries[t].size()) {
        // printf("t=%d\n",t);
        int okay=0;
        FOR_(i,1,n) cur[i]=0,mark[i]=1;
        FOR_(i,1,m) {
            prefsum[i]=prefsum[i-1]+okay*(T[i]-T[i-1]);
            if (P[i]==t) okay^=1;
            mark[P[i]]=-mark[P[i]];
            if (mark[P[i]]==-1) cur[P[i]]-=prefsum[i];
            else cur[P[i]]+=prefsum[i];
            // printf("%d ",prefsum[i]);
        }
        // puts("<- prefsum");
        // FOR_(i,1,n) printf("%d ",cur[i]); puts("<- res");
        for (auto [r,id]:queries[t]) result[id]=cur[r];
    }
    FOR_(i,1,q) printf("%d\n",result[i]);

    return 0;
}
int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(0), cout.tie(0);
    int T = 1;
    // cin>>T;
    // scanf("%d",&T);
    startTimer();
    FOR_(_, 1, T) { solve(); }
    // printTimer();
}
/*
*/

提出情報

提出日時
問題 G - AtCoder Office
ユーザ zlc1114
言語 C++ 20 (gcc 12.2)
得点 575
コード長 5534 Byte
結果 AC
実行時間 1339 ms
メモリ 21144 KiB

コンパイルエラー

Main.cpp: In function ‘int solve()’:
Main.cpp:109:28: warning: comparison of integer expressions of different signedness: ‘std::vector<std::array<int, 2> >::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  109 |         if (items[a].size()<=B&&items[b].size()<=B) {
      |             ~~~~~~~~~~~~~~~^~~
Main.cpp:109:48: warning: comparison of integer expressions of different signedness: ‘std::vector<std::array<int, 2> >::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  109 |         if (items[a].size()<=B&&items[b].size()<=B) {
      |                                 ~~~~~~~~~~~~~~~^~~
Main.cpp:111:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::array<int, 2> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  111 |             while (x<items[a].size()&&y<items[b].size()) {
      |                    ~^~~~~~~~~~~~~~~~
Main.cpp:111:40: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::array<int, 2> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  111 |             while (x<items[a].size()&&y<items[b].size()) {
      |                                       ~^~~~~~~~~~~~~~~~
Main.cpp:115:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::array<int, 2> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  115 |                 while (x<items[a].size()&&items[a][x][0]<=nxt) x++;
      |                        ~^~~~~~~~~~~~~~~~
Main.cpp:116:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::array<int, 2> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  116 |                 while (y<items[b].size()&&items[b][y][0]<=nxt) y++;
      |                        ~^~~~~~~~~~~~~~~~
Main.cpp:121:32: warning: comparison of integer expressions of different signedness: ‘std::vector<std::array<int, 2> >::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  121 |             if (items[a].size()>=B) queries[a].push_back({b,i});
      |                 ~~~~~~~~~~~~~~~^~~
Main.cpp:86:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   86 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:89:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   89 |     scanf("%d",&m);
      |     ~~~~~^~~~~~~~~
Main.cpp:94:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   94 |         scanf("%d%d",&t,&p);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:101:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  101 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
Main.cpp:108:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  108 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 575 / 575
結果
AC × 2
AC × 78
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt, 01_random_65.txt, 01_random_66.txt, 01_random_67.txt, 01_random_68.txt, 01_random_69.txt, 02_handmade_68.txt, 02_handmade_69.txt, 02_handmade_70.txt, 02_handmade_71.txt, 02_handmade_72.txt, 02_handmade_73.txt, 02_handmade_74.txt, 02_handmade_75.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3932 KiB
00_sample_01.txt AC 1 ms 3872 KiB
01_random_02.txt AC 105 ms 20212 KiB
01_random_03.txt AC 99 ms 20160 KiB
01_random_04.txt AC 100 ms 20180 KiB
01_random_05.txt AC 98 ms 20272 KiB
01_random_06.txt AC 97 ms 20192 KiB
01_random_07.txt AC 107 ms 20212 KiB
01_random_08.txt AC 98 ms 20236 KiB
01_random_09.txt AC 103 ms 20408 KiB
01_random_10.txt AC 97 ms 20236 KiB
01_random_11.txt AC 100 ms 20344 KiB
01_random_12.txt AC 105 ms 20352 KiB
01_random_13.txt AC 97 ms 20372 KiB
01_random_14.txt AC 235 ms 10068 KiB
01_random_15.txt AC 25 ms 10780 KiB
01_random_16.txt AC 57 ms 9408 KiB
01_random_17.txt AC 60 ms 7836 KiB
01_random_18.txt AC 61 ms 18028 KiB
01_random_19.txt AC 56 ms 10104 KiB
01_random_20.txt AC 58 ms 11400 KiB
01_random_21.txt AC 51 ms 9976 KiB
01_random_22.txt AC 52 ms 9552 KiB
01_random_23.txt AC 58 ms 10580 KiB
01_random_24.txt AC 77 ms 10384 KiB
01_random_25.txt AC 216 ms 10584 KiB
01_random_26.txt AC 212 ms 10588 KiB
01_random_27.txt AC 346 ms 10272 KiB
01_random_28.txt AC 335 ms 9444 KiB
01_random_29.txt AC 344 ms 9520 KiB
01_random_30.txt AC 138 ms 9472 KiB
01_random_31.txt AC 98 ms 10660 KiB
01_random_32.txt AC 101 ms 17984 KiB
01_random_33.txt AC 52 ms 11032 KiB
01_random_34.txt AC 52 ms 10488 KiB
01_random_35.txt AC 52 ms 9628 KiB
01_random_36.txt AC 58 ms 10820 KiB
01_random_37.txt AC 59 ms 10592 KiB
01_random_38.txt AC 74 ms 10872 KiB
01_random_39.txt AC 75 ms 10536 KiB
01_random_40.txt AC 122 ms 10676 KiB
01_random_41.txt AC 123 ms 10792 KiB
01_random_42.txt AC 199 ms 11164 KiB
01_random_43.txt AC 471 ms 10052 KiB
01_random_44.txt AC 464 ms 9700 KiB
01_random_45.txt AC 226 ms 9436 KiB
01_random_46.txt AC 124 ms 10764 KiB
01_random_47.txt AC 111 ms 20360 KiB
01_random_48.txt AC 71 ms 12592 KiB
01_random_49.txt AC 84 ms 12732 KiB
01_random_50.txt AC 89 ms 15356 KiB
01_random_51.txt AC 92 ms 15140 KiB
01_random_52.txt AC 88 ms 15172 KiB
01_random_53.txt AC 89 ms 15392 KiB
01_random_54.txt AC 61 ms 12508 KiB
01_random_55.txt AC 66 ms 13184 KiB
01_random_56.txt AC 222 ms 14116 KiB
01_random_57.txt AC 1339 ms 11228 KiB
01_random_58.txt AC 1066 ms 11588 KiB
01_random_59.txt AC 917 ms 12028 KiB
01_random_60.txt AC 885 ms 12120 KiB
01_random_61.txt AC 61 ms 12584 KiB
01_random_62.txt AC 62 ms 12404 KiB
01_random_63.txt AC 224 ms 14316 KiB
01_random_64.txt AC 651 ms 11024 KiB
01_random_65.txt AC 524 ms 11332 KiB
01_random_66.txt AC 450 ms 11952 KiB
01_random_67.txt AC 443 ms 11760 KiB
01_random_68.txt AC 65 ms 20492 KiB
01_random_69.txt AC 65 ms 20604 KiB
02_handmade_68.txt AC 66 ms 20624 KiB
02_handmade_69.txt AC 66 ms 20648 KiB
02_handmade_70.txt AC 91 ms 21144 KiB
02_handmade_71.txt AC 88 ms 20676 KiB
02_handmade_72.txt AC 83 ms 19896 KiB
02_handmade_73.txt AC 94 ms 20968 KiB
02_handmade_74.txt AC 94 ms 20664 KiB
02_handmade_75.txt AC 86 ms 19988 KiB