Last active
August 29, 2015 14:20
-
-
Save zsrinivas/eb69b27b85430f9c9746 to your computer and use it in GitHub Desktop.
spoj ⟿ classical ⟿ updateit ⟿ Update the array !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define builtin_gcd __gcd | |
static struct IO { | |
char tmp[1 << 10]; | |
// fast input routines | |
char cur; | |
// #define nextChar() (cur = getc_unlocked(stdin)) | |
// #define peekChar() (cur) | |
inline char nextChar() { | |
return cur = getc_unlocked(stdin); | |
} | |
inline char peekChar() { | |
return cur; | |
} | |
inline operator bool() { | |
return peekChar(); | |
} | |
inline static bool isBlank(char c) { | |
return (c < '-' && c > 0); | |
} | |
inline bool skipBlanks() { | |
while (isBlank(nextChar())); | |
return peekChar() > 0; | |
} | |
inline IO& operator >> (char & c) { | |
c = nextChar(); | |
return *this; | |
} | |
inline IO& operator >> (char * buf) { | |
if (skipBlanks()) { | |
if (peekChar()) { | |
*(buf++) = peekChar(); | |
while (!isBlank(nextChar())) | |
*(buf++) = peekChar(); | |
} | |
*(buf++) = 0; | |
} | |
return *this; | |
} | |
inline IO& operator >> (string & s) { | |
if (skipBlanks()) { | |
s.clear(); | |
s += peekChar(); | |
while (!isBlank(nextChar())) | |
s += peekChar(); | |
} | |
return *this; | |
} | |
inline IO& operator >> (double & d) { | |
if ((*this) >> tmp) | |
sscanf(tmp, "%lf", &d); | |
return *this; | |
} | |
#define defineInFor(intType) \ | |
inline IO& operator >>(intType & n) { \ | |
if (skipBlanks()) { \ | |
int sign = +1; \ | |
if (peekChar() == '-') { \ | |
sign = -1; \ | |
n = nextChar() - '0'; \ | |
} else \ | |
n = peekChar() - '0'; \ | |
while (!isBlank(nextChar())) { \ | |
n += n + (n << 3) + peekChar() - 48; \ | |
} \ | |
n *= sign; \ | |
} \ | |
return *this; \ | |
} | |
defineInFor(int) | |
defineInFor(unsigned int) | |
defineInFor(long long) | |
// fast output routines | |
//#define putChar(c) putc_unlocked((c), stdout) | |
inline void putChar(char c) { | |
putc_unlocked(c, stdout); | |
} | |
inline IO& operator << (char c) { | |
putChar(c); | |
return *this; | |
} | |
inline IO& operator << (const char * s) { | |
while (*s) putChar(*s++); | |
return *this; | |
} | |
inline IO& operator << (const string & s) { | |
for (int i = 0; i < (int)s.size(); ++i) | |
putChar(s[i]); | |
return *this; | |
} | |
char * toString(double d) { | |
sprintf(tmp, "%lf%c", d, '\0'); | |
return tmp; | |
} | |
inline IO& operator << (double d) { | |
return (*this) << toString(d); | |
} | |
#define defineOutFor(intType) \ | |
inline char * toString(intType n) { \ | |
char * p = (tmp + 30); \ | |
if (n) { \ | |
bool isNeg = 0; \ | |
if (n < 0) isNeg = 1, n = -n; \ | |
while (n) \ | |
*--p = (n % 10) + '0', n /= 10; \ | |
if (isNeg) *--p = '-'; \ | |
} else *--p = '0'; \ | |
return p; \ | |
} \ | |
inline IO& operator << (intType n) { return (*this) << toString(n); } | |
defineOutFor(int) | |
defineOutFor(long long) | |
#define endl ('\n') | |
#define cout __io__ | |
#define cin __io__ | |
// dict output | |
template<class T, class U> | |
inline IO& operator << (map<T, U>& p) { | |
(*this) << "{"; | |
for (typename map<T, U>::iterator it = p.begin(); it != p.end(); it++) { | |
(*this) << it->first << ": " << it->second << ", "; | |
} | |
(*this) << "}"; | |
return *this; | |
} | |
// pair input | |
template<class T, class U> | |
inline IO& operator >> (pair<T, U>& p) { | |
(*this) >> p.first >> p.second; | |
return *this; | |
} | |
// pair output | |
template<class T, class U> | |
inline IO& operator << (pair<T, U>& p) { | |
(*this) << '(' << p.first << ", " << p.second << ')'; | |
return *this; | |
} | |
// pair input | |
template<class T, class U> | |
inline IO& operator >> (const pair<T, U>& p) { | |
(*this) >> p.first >> p.second; | |
return *this; | |
} | |
// pair output | |
template<class T, class U> | |
inline IO& operator << (const pair<T, U>& p) { | |
(*this) << '(' << p.first << ", " << p.second << ')'; | |
return *this; | |
} | |
// vector input | |
template<class T> | |
inline IO& operator >> (vector<T>& d) { | |
for (size_t i = 0; i < d.size(); ++i) | |
(*this) >> d[i]; | |
return *this; | |
} | |
// vector output | |
template<class T> | |
inline IO& operator << (vector<T>& d) { | |
(*this) << "["; | |
for (size_t i = 0; i < d.size(); ++i) | |
(*this) << d[i] << ", "; | |
(*this) << "]"; | |
return *this; | |
} | |
} __io__; | |
int main() { | |
int testcases; | |
cin >> testcases; | |
while(testcases--) { | |
int32_t n, u; | |
cin >> n >> u; | |
vector<int32_t> arr(n + 1); | |
while(u--) { | |
int32_t l, r, v; | |
cin >> l >> r >> v; | |
arr[l] += v; | |
arr[r + 1] -= v; | |
} | |
for (int x = 1; x < n + 1; ++x) { | |
arr[x] += arr[x - 1]; | |
} | |
int32_t q; | |
cin >> q; | |
for (int32_t _ = 0; _ < q; ++_) { | |
int32_t query; | |
cin >> query; | |
cout << arr[query] << endl; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- encoding: utf-8 -*- | |
# pylint: disable=invalid-name,missing-docstring,bad-builtin | |
from sys import stdin | |
from itertools import imap | |
def main(): | |
dstream = imap(int, stdin.read().split()) | |
for _ in xrange(next(dstream)): | |
n, u = next(dstream), next(dstream) | |
arr = [0]*(n + 1) | |
for _ in xrange(u): | |
l, r, v = next(dstream), next(dstream), next(dstream) | |
arr[l] += v | |
arr[r + 1] -= v | |
for x in xrange(1, n + 1): | |
arr[x] += arr[x - 1] | |
for _ in xrange(next(dstream)): | |
print arr[next(dstream)] | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment