跳到正文

OP03_2

1054015

https://atcoder.jp/users/cmq2014

在洛谷打开
资料、奖项与版本

资料

编号
1054015
抓取

奖项

2024 CSP-J
二等奖

陶片放逐

− 自由发言
+ 进入主站
− 进入主站
− 进入主站

查看记录

C++
#include <bits/stdc++.h>
#define int long long
#define mk make_pair
#define PII pair<int,int>
#define FOR(i,j,k) for(int i=(j);i<=(k);++i)
#define ROF(i,j,k) for(int i=(j);i>=(k);--i)
#define FOI(a,b) for(auto a : b)
#define wh while
#define inf 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define snd second
#define fst first
#define pb push_back
#define CI const int
#define NP namespace
using NP std;
int quickpow(int a,int b)
{
	int ans=1;
	wh(b)
	{
		if(b&1)ans=ans*a;
        a=a*a;
		b>>=1;
	}
	return ans;
}

signed main(void)
{

    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	IOS

    return false;
}







C++
#define INPUT_OPTIMIZE
#define OUTPUT_OPTIMIZE
#define INLINE_OPTIMIZE
#define USING_MMAP
#define ONLY_BLANK
#ifdef USING_MMAP
 #ifdef __unix__
  #define UINT16_OPTIMIZE 
 #endif
#endif
namespace IO {
 constexpr int Read_Bufsize = 1 << 21 | 20;
 constexpr int Write_Bufsize = 1 << 21 | 20;
#ifdef INLINE_OPTIMIZE
 #define IOINLINE [[gnu::always_inline]] inline
#else
 #define IOINLINE inline
#endif
#define mmap_init() 0
#ifdef INPUT_OPTIMIZE
 #ifdef __unix__
  #ifdef USING_MMAP
   #include <fcntl.h>
   #include <sys/mman.h>
   #include <sys/stat.h>
   #include <unistd.h>
   #undef mmap_init
   constexpr int fd = 0;
   inline static const unsigned char *p1; struct stat stat_;
   IOINLINE void mmap_init() {
    fstat(fd, &stat_);
    p1 = (const unsigned char *)mmap(NULL, stat_.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
   }
   #define getchar() (*p1++)
  #else
   static unsigned char buf[Read_Bufsize], *p1 = buf, *p2 = buf;
   #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread_unlocked(buf, 1, Read_Bufsize, stdin), p1 == p2) ? EOF : *p1++)
  #endif
 #else
  static unsigned char buf[Read_Bufsize], *p1 = buf, *p2 = buf;
  #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, Read_Bufsize, stdin), p1 == p2) ? EOF : *p1++)
 #endif
#endif
#ifdef UINT16_OPTIMIZE
 struct uint16_table {
  int table[65540];
  constexpr uint16_table() : table{} {
   for(int i = 0; i < 65536; ++i) table[i] = -1;
   for(int i = 48; i != 58; ++i)
    for(int j = 48; j != 58; ++j)
     table[i << 8 | j] = (j & 15) * 10 + (i & 15);
  }
 };
 constexpr uint16_table Table;
 #define TABLE Table.table
#endif
 IOINLINE bool read(unsigned char *t) {
  memset(t, 0, sizeof t);
  unsigned char *pd = t, c = getchar();
  while (isspace(c)) c = getchar();
  while (!isspace(c)) *pd++ = c, c = getchar();
  return c == EOF;
 }
 template <typename T> 
 IOINLINE bool read(T &t) {
  t=0;T sgn=1;
  int c = getchar();
  #ifdef UINT16_OPTIMIZE
   #ifdef ONLY_BLANK
    if(c<=32) c = getchar();
    if(c==45) sgn = -1, c = getchar();
   #else
    while(!isdigit(c)) {if(c == 45) sgn *= -1; c = getchar();}
   #endif
   #define xio_next __builtin_expect(!!~TABLE[*(uint16_t*)(p1 - 1)],1) && ((t = TABLE[*(uint16_t*)(p1 - 1)], p1+=2))
   #define io_next (~TABLE[*(uint16_t*)(p1 - 1)]) && ((t = t * 100 + TABLE[*(uint16_t*)(p1 - 1)], p1+=2))
   xio_next && io_next && io_next && io_next;
   c = *(p1 - 1);
   #ifdef ONLY_BLANK
    if(c>32) t = t * 10 + (c & 15), ++p1;
   #else
    if(isdigit(c)) t = t * 10 + (c & 15), ++p1;
   #endif
  #else
   #ifdef ONLY_BLANK
    while(c<=32) c = getchar();
    if(c==45) sgn = -1, c=getchar();
    while(c>32) t = t * 10 + (c & 15), c = getchar();
   #else
    while(!isdigit(c)) {if(c == 45)sgn *= -1;c = getchar();}
    while(isdigit(c)) t = t * 10 + (c & 15), c = getchar();
   #endif
  #endif
  t*=sgn;
  return c == EOF;
 }
 template <typename T, typename... Args> 
 IOINLINE bool read(T &t, Args&... args) {
  return read(t) ? 1 : read(args...);
 }
#ifdef OUTPUT_OPTIMIZE
 static unsigned char outbuf[Write_Bufsize], *out = outbuf;
 #define putchar(x) (*out++ = x)
 #define flush() fwrite(outbuf, 1, out - outbuf, stdout)
 struct auto_flush { auto_flush() { atexit([]() {flush();}); } } initializer;
#else 
 #define flush() 0
#endif
 template <typename T> 
 IOINLINE void write(T x) {
  if (!x) return putchar(48), void();
  static unsigned char t[9], p = 0;
  while (x) t[++p] = (x % 10) & 15, x /= 10;
  while (p) putchar(t[p--]);
 }
} using namespace IO;
int main() {
 mmap_init();
  //Code
 }
C++
// author : OP03-2Q0532B202508201103
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define i64 __int128_t
#define endl '\n'
#define INF 0x3f3f3f3f3f3f3f3f
using pii = pair<int,int>;
mt19937_64 rng(random_device{}());
int dx[5]={0,0,0,1,-1};
int dy[5]={0,1,-1,0,0};
int pows(int a,int b)
{
    int ret=1;
    while(b){
        if(b%2==1) ret=(ret*a);
        a=a*a;
        b/=2;
    }
    return ret;
}
void solve()
{
	
	
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int num=1;
//    cin>>num;
    while(num--)
    {
        solve();
    }
    return 0;
}

ICPC=International Central Polygon Competition=国际中央多边形比赛

CCF=Chinese Can Fly=中国人能飞

C++
#include<bits/stdc++.h>
#define int long long
#define mk make_pair
#define PII pair<int,int>
#define FOR(i,j,k) for(int i=(j);i<=(k);++i)
#define ROF(i,j,k) for(int i=(j);i>=(k);--i)
#define FOI(a,b) for(auto a : b)
#define wh while
#define inf 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define snd second
#define fst first
#define pb push_back
#define CI const int
#define NP namespace
using NP std;
struct BigInt{
    vector<int>d;
    static const int B=10000;
    static const int W=4;
    bool neg=false;
    BigInt(int n=0){
        if(n<0){neg=true;n=-n;}
        do{d.pb(n%B);n/=B;}wh(n>0);
        trim();
    }
    BigInt(const string&s){
        string t=s;
        if(t[0]=='-'){neg=true;t=t.substr(1);}
        int l=t.size();
        for(int i=l;i>0;i-=W){
            int st=max(0ll,(long long)i-W);
            d.pb(stoi(t.substr(st,i-st)));
        }
        trim();
    }
    void trim(){
        wh(d.size()>1&&d.back()==0)d.pop_back();
        if(d.size()==1&&d[0]==0)neg=false;
    }
    bool operator<(const BigInt&b)const{
        if(neg!=b.neg)return neg>b.neg;
        if(d.size()!=b.d.size())return neg?(d.size()>b.d.size()):(d.size()<b.d.size());
        for(int i=d.size()-1;i>=0;--i)if(d[i]!=b.d[i])return neg?(d[i]>b.d[i]):(d[i]<b.d[i]);
        return false;
    }
    bool operator==(const BigInt&b)const{return neg==b.neg&&d==b.d;}
    bool operator!=(const BigInt&b)const{return !(*this==b);}
    bool operator<=(const BigInt&b)const{return !(b<*this);}
    BigInt operator+(const BigInt&b)const{
        if(neg!=b.neg){
            if(neg){BigInt t=*this;t.neg=false;return b-t;}
            BigInt t=b;t.neg=false;return *this-t;
        }
        BigInt r;r.neg=neg;r.d.clear();int c=0;size_t m=max(d.size(),b.d.size());
        for(size_t i=0;i<m||c;++i){
            if(i<d.size())c+=d[i];if(i<b.d.size())c+=b.d[i];
            r.d.pb(c%B);c/=B;
        }
        r.trim();return r;
    }
    BigInt operator-(const BigInt&b)const{
        if(neg!=b.neg){
            if(neg){BigInt t=*this;t.neg=false;return -(t+b);}
            BigInt t=b;t.neg=false;return *this+t;
        }
        if(*this<b){BigInt t=b-*this;t.neg=!neg;t.trim();return t;}
        BigInt r;r.neg=neg;r.d.clear();int c=0;
        for(size_t i=0;i<d.size();++i){
            int cur=d[i]-c;if(i<b.d.size())cur-=b.d[i];
            if(cur<0){cur+=B;c=1;}else c=0;r.d.pb(cur);
        }
        r.trim();return r;
    }
    BigInt operator-()const{BigInt r=*this;r.neg=!r.neg;r.trim();return r;}
    BigInt operator*(const BigInt&b)const{
        BigInt r;r.neg=neg!=b.neg;r.d.assign(d.size()+b.d.size(),0);
        for(size_t i=0;i<d.size();++i){
            int c=0;
            for(size_t j=0;j<b.d.size()||c;++j){
                long long cur=(long long)r.d[i+j]+(long long)d[i]*(j<b.d.size()?b.d[j]:0)+c;
                r.d[i+j]=cur%B;c=cur/B;
            }
        }
        r.trim();return r;
    }
    BigInt operator/(const BigInt&b)const{
        if(b==BigInt(0))return BigInt(0);
        BigInt q,rm;q.neg=neg!=b.neg;
        for(int i=(int)d.size()-1;i>=0;--i){
            rm=rm*BigInt(B)+BigInt(d[i]);
            int l=0,r=B-1,m;
            wh(l<r){m=(l+r+1)/2;if(b*BigInt(m)<=rm)l=m;else r=m-1;}
            q.d.pb(l);rm=rm-b*BigInt(l);
        }
        reverse(q.d.begin(),q.d.end());q.trim();return q;
    }
    BigInt operator%(const BigInt&b)const{
        BigInt r=*this-(*this/b)*b;r.neg=neg;r.trim();return r;
    }
    friend ostream&operator<<(ostream&o,const BigInt&n){
        if(n.neg&&!(n.d.size()==1&&n.d[0]==0))o<<"-";
        o<<n.d.back();
        for(int i=(int)n.d.size()-2;i>=0;--i)o<<setw(BigInt::W)<<setfill('0')<<n.d[i];
        return o;
    }
    friend istream&operator>>(istream&i,BigInt&n){
        string s;i>>s;n=BigInt(s);return i;
    }
};
signed main(void){
    IOS;
    BigInt a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
    cout<<a-b<<endl;
    cout<<a*b<<endl;
    cout<<a/b<<endl;
    cout<<a%b<<endl;
    return false;
}
共 1 篇
  1. 题解

    题解:P17011 [GESP202606 五级] 晚宴

    该算法通过两层循环遍历数组中所有元素对,利用__gcd函数判断两个数是否互质(即最大公约数为1),若满足条件则比较其和并更新最大值。最终输出所有互质对中的最大和。代码中使用了避免重复检查的循环结构(i从1到n,j从i+1到n),并采用long long类型防止溢出。