답안 #628642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628642 2022-08-13T14:43:10 Z Iwanttobreakfree Fancy Fence (CEOI20_fancyfence) C++17
0 / 100
2 ms 340 KB
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int mod=1e9+7;
int main(){
    int n;
    cin>>n;
    vector<int> v(n),h(n);
    map<int,int> mp;
    for(int& i:v)cin>>i;
    for(int& i:h)cin>>i;
    for(int i=0;i<n;i++){
        mp[h[i]]=(mp[h[i]]+v[i])%mod;
    }
    vector<pair<int,int>> comp;
    for(auto x:mp)comp.push_back(x);
    for(int i=comp.size()-1;i>0;i--)comp[i-1].second=(comp[i-1].second+comp[i].second)%mod;
    long long ans=0;
    for(int i=0;i<comp.size();i++){
        pair<int,int> x=comp[i];
        //cout<<(1ll*x.first*(x.first+1)/2)<<' '<<(1ll*x.second*(x.second+1)/2)<<'\n';
        ans+=(((1ll*x.first*(x.first+1)/2)%mod)*((1ll*x.second*(x.second+1)/2)%mod))%mod;
        if(i){
            pair<int,int> y=comp[i-1];
            ans-=(((1ll*y.first*(y.first+1)/2)%mod)*((1ll*x.second*(x.second+1)/2)%mod))%mod;
            if(ans<0)ans+=mod;
        }
    }
    cout<<ans;
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0;i<comp.size();i++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -