QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743719 | #9528. New Energy Vehicle | scallionsong | WA | 79ms | 12024kb | C++14 | 2.9kb | 2024-11-13 19:52:42 | 2024-11-13 19:52:42 |
Judging History
answer
bool M1;
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define LL __int128
#define db double
#define LD long double
#define Pii pair<int,int>
#define Pll pair<ll,ll>
#define Pull pair<ull,ull>
#define Pdb pair<db,db>
#define fir first
#define sec second
#define vec vector<int>
#define pb push_back
#define qlr cerr<<"qlr\n"
#define dyh cerr<<"dyh\n"
#define pc(x) __builtin_popcount(x)
#define uni(x,y) uniform_int_distribution<int>(x,y)(rng)
#define unl(x,y) uniform_int_distribution<ll>(x,y)(rng)
#define unr(x,y) uniform_real_distribution<double>(x,y)(rng)
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define UF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define look_memory cerr<<'\n'<<abs(&M1-&M2)/1024.0/1024<<'\n'
#define look_time cerr<<'\n'<<clock()*1.0/CLOCKS_PER_SEC<<'\n'
mt19937 rng(time(0)^(*new int));
const ll INF=0x3f3f3f3f3f3f3f3f;
const int Mod=998244353;
template<typename T>
inline void inc(T &a,T b){
if(b<0) b+=Mod;
a+=b;
if(a>=Mod) a-=Mod;
}
template<typename T>
inline void dec(T &a,T b){
if(b<0) b+=Mod;
a-=b;
if(a<0) a+=Mod;
}
template<typename T>
inline void muc(T &a,T b){
a=a*b%Mod;
}
template<typename T>
inline bool chkmin(T &a,T b){
if(a<=b) return false;
a=b;
return true;
}
template<typename T>
inline bool chkmax(T &a,T b){
if(a>=b) return false;
a=b;
return true;
}
int T,n,m;
ll ans;
int a[100010],val[100010];
Pii b[100010];
vec t[100010];
struct Pq{
priority_queue<Pii,vector<Pii>,greater<Pii>> q1,q2;
void push(Pii x){
q1.push(x);
}
void pop(){
q1.pop();
}
void del(Pii x){
q2.push(x);
while(!q2.empty()&&q1.top()==q2.top()) q1.pop(),q2.pop();
}
Pii top(){
return q1.top();
}
bool empty(){
return q1.empty();
}
}q;
void solve(){
cin>>n>>m;
F(i,1,n) cin>>a[i];
F(i,1,m) cin>>b[i].fir>>b[i].sec;
F(i,1,n) val[i]=a[i];
F(i,1,n) t[i].clear();
F(i,1,n) t[i].pb(n+1);
UF(i,m,1) t[b[i].sec].pb(i);
while(!q.empty()) q.pop();
F(i,1,n) q.push({t[i].back(),i});
F(i,1,m){
int d=b[i].fir-b[i-1].fir;
while(!q.empty()&&d){
int u=q.top().sec;q.pop();
int lim=min(d,val[u]);
d-=lim;
val[u]-=lim;
if(val[u]) q.push({t[u].back(),u});
}
if(d) {cout<<b[i].fir-d<<'\n';return;}
int x=b[i].sec;
if(val[x]) q.del({i,x});
val[x]=a[x];
t[x].pop_back();
q.push({t[x].back(),x});
}
ans=b[m].fir;
F(i,1,n) ans+=val[i];
cout<<ans<<'\n';
}
bool M2;
int main(){
// freopen("count.in","r",stdin);
// freopen("count.out","w",stdout);
srand(time(0)^(*new int));
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>T;
while(T--) solve();
look_memory;
look_time;
return 0;
}
/*
g++ C1.cpp -o C1 -std=c++14 -O2&&./C1
2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6888kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
12 9
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 7688kb
input:
6 3 2 2 2 2 6 1 7 1 2 2 3 3 2 1 6 2 2 3 2 2 5 1 7 2 9 1 2 2 3 3 2 1 6 2 1 1 999999999 1000000000 1 1 1 1000000000 1000000000 1
output:
9 11 4 11 999999999 2000000000
result:
ok 6 lines
Test #3:
score: -100
Wrong Answer
time: 79ms
memory: 12024kb
input:
10 230 8042 599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...
output:
1436186 1525298 1155230 1477893 1427531 1504786 1010527 1508161 1114634 1072253
result:
wrong answer 1st lines differ - expected: '1543020', found: '1436186'