結果
| 問題 | No.3560 Giant Salamander |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-29 20:11:46 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 305 ms / 2,000 ms |
| コード長 | 3,616 bytes |
| 記録 | |
| コンパイル時間 | 2,193 ms |
| コンパイル使用メモリ | 345,032 KB |
| 実行使用メモリ | 34,228 KB |
| 最終ジャッジ日時 | 2026-05-29 20:11:54 |
| 合計ジャッジ時間 | 7,823 ms |
|
ジャッジサーバーID (参考情報) |
judge4_1 / judge1_0 |
| 純コード判定待ち |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 5 % | AC * 5 |
| 部分点2 | 20 % | AC * 6 |
| 部分点3 | 15 % | AC * 11 |
| 部分点4 | 40 % | AC * 22 |
| 満点 | 20 % | AC * 35 |
| 合計 | 100 点 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include<atcoder/lazysegtree>
//高速化
struct ponjuice{ponjuice(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}}PonJuice;
//#define endl '\n' //インタラクティブ問題の時は消す
//型
using ll = long long;
using ld = long double;
template<class T>using vc = vector<T>; template<class T>using vvc = vc<vc<T>>; template<class T>using vvvc = vvc<vc<T>>;
using vi = vc<int>; using vvi = vvc<int>; using vvvi = vvvc<int>;
using vl = vc<ll>; using vvl = vvc<ll>; using vvvl = vvvc<ll>;
using pi = pair<int, int>; using pl = pair<ll, ll>;
using ull = unsigned ll;
template<class T>using priq = priority_queue<T>;
template<class T>using priqg = priority_queue<T, vc<T>, greater<T>>;
// for文
#define overload4(a, b, c, d, e, ...) e
#define rep1(n) for(ll i = 0; i < n; i++)
#define rep2(i, n) for(ll i = 0; i < n; i++)
#define rep3(i, a, b) for(ll i = a; i < b; i++)
#define rep4(i, a, b, step) for(ll i = a; i < b; i+= step)
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define per1(n) for(ll i = n-1; i >= 0; i--)
#define per2(i, n) for(ll i = n-1; i >= 0; i--)
#define per3(i, a, b) for(ll i = b-1; i >= a; i--)
#define per4(i, a, b, step) for(ll i = b-1; i >= a; i-= step)
#define per(...) overload4(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__)
//関数
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define si(x) (ll)(x).size()
template<class S, class T>inline bool chmax(S& a, T b){return a < b && ( a = b , true);}
template<class S, class T>inline bool chmin(S& a, T b){return a > b && ( a = b , true);}
inline void yes(){cout << "Yes\n";}
inline void no(){cout << "No\n";}
inline void yesno(bool y = true){if(y)yes();else no();}
//定数
constexpr ll mod = 998244353;
constexpr ll minf=-(1<<29);
constexpr ll inf=(1<<29);
constexpr ll MINF=-(1LL<<60);
constexpr ll INF=(1LL<<60);
const int dx[4] ={-1, 0, 1, 0};
const int dy[4] ={ 0, 1, 0,-1};
const int dx8[8] ={-1,-1,-1, 0, 1, 1, 1, 0};
const int dy8[8] ={-1, 0, 1, 1, 1, 0,-1,-1};
void solve();
int main() {
int t = 1;
cin >>t;
while(t--)solve();
}
using S=ll;
using F=ll;
const S Inf = 8e18;
const F ID = 0;
S op(S a, S b){ return min(a,b); }
S e(){ return Inf; }
S mapping(F f, S x){ return f+x; }
F composition(F f, F g){ return f+g; }
F id(){ return ID; }
void solve(){
ll n,m;
cin >> n >> m;
vector<ll> a(m), b(m);
rep(i,0,m) cin >> a[i] >> b[i];
if(m == 1) {
cout << "Yes" << endl;
return;
}
atcoder::lazy_segtree<F,op,e,S,mapping,composition,id> seg(m*2);
atcoder::lazy_segtree<F,op,e,S,mapping,composition,id> seg2(m*2);
seg.set(0, n+a[1] - a[m-1] - 1 - b[0]);
seg2.set(0, a[1] - a[0]-1 - seg.get(0));
rep(i,1,m*2) {
ll add = (a[(i+1)%m] - a[i%m]);
if(add < 0) add += n;
seg.set(i, seg.get(i-1) + add - b[i%m]);
seg2.set(i, (a[(i+1)%m] - a[i%m]>=0?a[(i+1)%m] - a[i%m]:a[(i+1)%m] - a[i%m]+n)-1 - seg.get(i));
}
// rep(i,0,m*2) cout << seg.get(i) << " "; cout << endl;
// rep(i,0,m*2) cout << seg2.get(i) << " "; cout << endl;
bool yes = false;
rep(i,0,m) {
ll diff = a[(i+1)%m] - a[(i+m-1)%m] - 1;
if(diff < 0) diff += n;
diff -= b[i];
diff = diff - seg.get(i);
seg.apply(i, m*2, diff);
seg2.apply(i, m*2, -diff);
if(seg.prod(i, i+m) >= 0 && seg2.prod(i,i+m) >= 0) {
yes = true;
}
}
cout << (yes?"Yes":"No") << endl;
}