QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133893 | #4940. Token Distance | ywhovo | WA | 14ms | 11288kb | C++20 | 3.0kb | 2023-08-02 16:44:38 | 2023-08-02 16:44:41 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define iloveds std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
typedef long long ll ;
const int N = 1e5 + 100;
const int mod = 1e9 + 7;
const int base = 666;
int n, q, a[N];
ll qpow(ll x, ll y){
ll ans = 1;
while(y){
if(y & 1){
ans = ans * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return ans % mod;
}
struct Info{
int mi, mx, h;
}seg[N << 2];
Info operator + (const Info &a, const Info &b){
Info c;
c.mx = max(a.mx, b.mx);
c.mi = min(a.mi, b.mi);
c.h = a.h + b.h % mod;
return c;
}
void up(int id){
seg[id] = seg[id << 1] + seg[id << 1 | 1];
}
void build(int id, int l, int r){
if(l == r){
seg[id] = {a[l], a[l], qpow(base, a[l])};
return;
}
int mid = (l + r) >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
up(id);
}
void change(int id, int l, int r, int pos, int val){
if(l == r){
seg[id] = {val, val, qpow(base, val)};
return;
}
int mid = (l + r) >> 1;
if(pos <= mid){
change(id << 1, l, mid, pos, val);
}else{
change(id << 1 | 1, mid + 1, r, pos, val);
}
up(id);
}
Info query(int id, int l, int r, int ql, int qr){
if(ql == l && qr == r) return seg[id];
int mid = (l + r) >> 1;
if(qr <= mid){
return query(id << 1, l, mid, ql, qr);
}else if(ql > mid){
return query(id << 1 | 1, mid + 1, r, ql, qr);
}else{
return query(id << 1, l, mid, ql, mid) + query(id << 1 | 1, mid + 1, r, mid + 1, qr);
}
}
signed main(){
iloveds;
cin >> n >> q;
for(int i = 1; i <= n ; i ++) cin >> a[i];
build(1, 1, n);
while(q --){
int ty;
cin >> ty;
if(ty == 1){
int x, y;
cin >> x >> y;
change(1, 1, n, x, y);
a[x] = y;
}else{
int l, r;
cin >> l >> r;
if(r - l + 1 <= 2) {
cout << "YES\n";
continue;
}
Info x = query(1, 1, n, l, r);
int s = x.mx - x.mi;
if(s % (r - l) != 0) {
cout << "NO\n";
continue;
}
int d = s / (r - l);
ll res;
if(d == 0){
res = (r - l + 1) * qpow(base, x.mi) % mod;
}else{
ll q = qpow(base, d);
ll frac1 = qpow(base, x.mi) * (1 - qpow(q, r - l + 1) + mod % mod) % mod;
ll frac2 = qpow(1 - q, mod - 2);
res = frac1 * frac2 % mod;
}
// cout << res << " " << x.h << "TTT\n";
if(res == x.h) {
cout << "YES\n";
}else{
cout << "NO\n";
}
}
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5476kb
input:
5 7 1 1 1 10 1 2 1 3 2 1 5 1 5 4 1 3 7 2 2 4 2 2 5 2 4 5
output:
YES NO NO YES YES
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3388kb
input:
2 1 0 1000000000 2 1 2
output:
YES
result:
ok single line: 'YES'
Test #3:
score: -100
Wrong Answer
time: 14ms
memory: 11288kb
input:
81473 13549 972586683 972586964 972587245 972587526 972587807 972588088 972588369 972588650 972588931 972589212 972589493 972589774 972590055 972590336 972590617 972590898 972591179 972591460 972591741 972592022 972592303 972592584 972592865 972593146 972593427 972593708 972593989 972594270 97259455...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'