提出 #14558518


ソースコード 拡げる

#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll  long long
#define ld long double
#define ui unsigned int
#define ull unsigned ll
#define foi(n) for(ll i=0;i<n;i++)
#define foj(n) for(ll j=0;j<n;j++)
#define fok(n) for(ll k=0;k<n;k++)
#pragma GCC optimize("O3", "unroll-loops")
#define fixed(); cout << fixed << setprecision(20);
#define fast(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

/*****************************************************************************/


#define graph          vector<vector<int>>
#define V              vector
typedef pair<int, int> pii;
typedef pair<ll, ll>   pll;
typedef V<int>         vi;
typedef V<ll>          vll;
typedef V<string>      vs;
typedef V<double>      vd;
typedef V<pii>         vpii;             
typedef V<pll>         vpll;             
typedef pair<int,pii>  piii;             
typedef priority_queue<pii, vector<pii>, greater<pii> > pqq;   

/*****************************************************************************/

#define mp                   make_pair
#define eb                   emplace_back
#define pb                   push_back
#define pf                   push_front
#define popb                 pop_back
#define popf                 pop_front
#define hashmap              unordered_map
#define hashset              unordered_set
#define lb                   lower_bound
#define ub                   upper_bound
#define all(a)               (a).begin(), (a).end()
#define rall(a)              (a).rbegin(), (a).rend()
#define ff                   first
#define ss                   second
#define lbpos(v,x)           (int)(lower_bound(all(v),x)-v.begin())//=v.size()==>No LB 
#define ubpos(v,x)           (int)(upper_bound(all(v),x)-v.begin())//=v.size()==>No UB

/*****************************************************************************/

//for declaring most used global variables and constants
ll mod=1e9+7;

//For Calculating nCr
template<typename T>
T nCr(T n, T r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    int  ans = 1,i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    } return ans;
}

//power optimized
template<typename T,typename T2>
T2 power(T x, T y) 
{ 
    if (y == 0)  return 1; 
    T2 res=power(x,y/2);
    if (y % 2)  return res*res*x;
    return res*res; 
}

//return number of set bits in a given number
template<typename T>
ll countSetBits(T n) 
{ 
    return __builtin_popcount (n);
}

//return true if number is prime
template<typename T>
bool isPrime(T n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n % 2 == 0 || n % 3 == 0)  return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
   return true; 
} 

//return true if string is palindrome
bool ispalindrome(string s)
{
    ll len=s.length();
    foi(len){
        if(s[i]!=s[len-i-1])
        return false;
    }
    return true;
}

//for string with space use std::getline(cin,string_name);
//*****************UVAISH ZAFRI(Rush_For_AC)**********************

int32_t main() {
    fast();fixed();
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
  
  ll n;
  cin>>n;
  map<ll,ll> m;
  ll a[n];
  foi(n){
  cin>>a[i];
  m[a[i]]++;
  }
  ll q;
  cin>>q;
  ll res=accumulate(a,a+n,0);
  
  while(q--){
      ll x,y;
      cin>>x>>y;
      res+=m[x]*(y-x);
      m[y]+=m[x];
      m[x]=0;
      
      cout<<res%mod<<endl;
  }
       return 0;
}

提出情報

提出日時
問題 D - Replacing
ユーザ UvaishZafri
言語 C++ (GCC 9.2.1)
得点 0
コード長 3731 Byte
結果 WA
実行時間 156 ms
メモリ 10200 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 400
結果
AC × 3
AC × 6
WA × 6
セット名 テストケース
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, test1.txt, test2.txt, test3.txt, test4.txt, test5.txt, test6.txt, test7.txt, test8.txt, test9.txt
ケース名 結果 実行時間 メモリ
sample1.txt AC 6 ms 3424 KiB
sample2.txt AC 3 ms 3564 KiB
sample3.txt AC 2 ms 3576 KiB
test1.txt AC 29 ms 3480 KiB
test2.txt AC 38 ms 3620 KiB
test3.txt WA 68 ms 4324 KiB
test4.txt WA 125 ms 9736 KiB
test5.txt AC 78 ms 8344 KiB
test6.txt WA 87 ms 4888 KiB
test7.txt WA 130 ms 9616 KiB
test8.txt WA 156 ms 10200 KiB
test9.txt WA 150 ms 9904 KiB