Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Some1258
Problemset: สร้อยสลับสี (ยาวมาก)
Language: cpp
Time: 0.064 second
Submitted On: 2026-06-28 18:04:43
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N;
int M,K;
cin>>N>>M>>K;
vector<long long> x(M);
for(int i=0;i<M;i++){
cin>>x[i];
}
long long ans=M;
for(int i=0;i<K;i++){
long long A;
int C;
cin>>A>>C;
long long cntLeft=upper_bound(x.begin(),x.end(), A)-x.begin();
int leftcolor=(cntLeft%2==0? 1:0);
if(A==N){
ans+=(leftcolor!=C);
}else{
long long cntRight=upper_bound(x.begin(),x.end(), A+1)-x.begin();
int rightcolor=(cntRight%2==0? 1:0);
int oldchange=(leftcolor!=rightcolor);
int newchange=(leftcolor!=C)+(C!=rightcolor);
ans+=newchange-oldchange;
}
}
cout<<ans;
}