Advertisement
dimon-torchila

Untitled

Dec 4th, 2022
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.26 KB | None | 0 0
  1. def main():
  2. a = int(input())
  3. arr = []
  4. for i in range(a):
  5. t = input().split(',')
  6. count = 0
  7. c = set()
  8. for i in range(3):
  9. for x in t[i]:
  10. if not x in c:
  11. count += 1
  12. c.add(x)
  13. """c = [False] * 52
  14. for i in range(3):
  15. for x in t[i]:
  16. if 'A' <= x <= 'Z':
  17. if not c[ord(x) - ord('A')]:
  18. count += 1
  19. c[ord(x) - ord('A')] = True
  20. else:
  21. if not c[ord(x) - ord('a') + 26]:
  22. count += 1
  23. c[ord(x) - ord('a') + 26] = True"""
  24. c2 = 0
  25. for i in range(3, 5):
  26. for x in t[i]:
  27. c2 += int(x)
  28. c2 *= 64
  29. c3 = ord(t[0][0]) - ord('A') + 1 if 'A' <= t[0][0] <= 'Z' else ord(t[0][0]) - ord('a') + 1
  30. c3 *= 256
  31. res = count + c2 + c3
  32. tmp = 16 * 16
  33. res %= tmp * 16
  34. s = ""
  35. while not tmp == 0:
  36. i = res // tmp
  37. res %= tmp
  38. #print(i)
  39. if i < 10:
  40. s += str(i)
  41. else:
  42. s += chr(ord('A') + i % 10)
  43. tmp //= 16
  44. print(s, end=' ')
  45.  
  46. if __name__ == '__main__':
  47. main()
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. #include <iostream>
  55. #include <algorithm>
  56. #include <map>
  57. #include <vector>
  58.  
  59.  
  60. using namespace std;
  61.  
  62.  
  63.  
  64. struct Date{
  65. int day;
  66. int hour;
  67. int minute;
  68. };
  69.  
  70.  
  71.  
  72. int main() {
  73. map<int, vector<pair<Date, char>>> logs;
  74. int LogCount;
  75. cin >> LogCount;
  76. for(int i = 0; i < LogCount; ++i){
  77. int day, hour, minute, id;
  78. char status;
  79. cin >> day >> hour >> minute >> id >> status;
  80. logs[id].push_back({{day, hour, minute}, status});
  81. }
  82. for(auto& x : logs){
  83. std::sort(x.second.begin(), x.second.end(), [](auto lhs, auto rhs){
  84. return lhs.first.day < rhs.first.day
  85. || (lhs.first.day == rhs.first.day && (lhs.first.hour < rhs.first.hour || ( lhs.first.hour == rhs.first.hour && lhs.first.minute < rhs.first.minute)));
  86. });
  87. }
  88.  
  89.  
  90.  
  91. for(const auto& x : logs){
  92. long long count = 0;
  93. Date date_begin = {0, 0, 0};
  94. Date date_end = {0, 0, 0};
  95. for(const auto& i : x.second){
  96. if(i.second == 'A')
  97. date_begin = i.first;
  98. if(i.second == 'C' || i.second == 'S') {
  99. date_end = i.first;
  100. count += (date_end.day*1440 + date_end.hour*60 + date_end.minute - (date_begin.day*1440 + date_begin.hour*60 + date_begin.minute));
  101. }
  102.  
  103.  
  104. }
  105. cout << count << ' ';
  106. }
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. #include<bits/stdc++.h>
  117. #define LINT long long int
  118.  
  119. using namespace std;
  120.  
  121.  
  122. struct ListNode {
  123. int val;
  124. ListNode *left;
  125. ListNode *right;
  126. ListNode *pred;
  127. ListNode() : val(0), left(nullptr), right(nullptr), pred(nullptr){}
  128. ListNode(int x) : val(x), left(nullptr), right(nullptr), pred(nullptr) {}
  129. ListNode(int x, ListNode *left, ListNode *right, ListNode *pred) : val(x), left(left), right(right), pred(pred){}
  130. };
  131.  
  132. vector<ListNode*> vc;
  133. void create_node(ListNode* head, int index, int s) {
  134. vc[index] = head;
  135. if (index * 2 <= s) {
  136. ListNode* left = new ListNode(index * 2, nullptr, nullptr, head);
  137. head->left = left;
  138. create_node(left, index * 2, s);
  139. }
  140. if (index * 2 + 1 <= s) {
  141. ListNode* right = new ListNode(index * 2 + 1, nullptr, nullptr, head);
  142. head->right = right;
  143. create_node(right, index * 2 + 1, s);
  144. }
  145. }
  146. ListNode* create_tree(int s) {
  147. if (s == 0)
  148. return nullptr;
  149. ListNode* root = new ListNode(1);
  150. create_node(root, 1, s);
  151. return root;
  152. }
  153.  
  154. void print_node(ListNode* head) {
  155. if (head->left != nullptr)
  156. print_node(head->left);
  157. cout << head->val << ' ';
  158. if (head->right != nullptr)
  159. print_node(head->right);
  160. }
  161. int main()
  162. {
  163. int a;
  164. cin >> a;
  165. vc.resize(a + 1);
  166. ListNode* root = create_tree(a);
  167. int b;
  168. cin >> b;
  169. for (int i = 0; i < b; ++i) {
  170. int t;
  171. cin >> t;
  172. ListNode* v = vc[t];
  173. if (v->pred == nullptr)
  174. continue;
  175. ListNode* p = v->pred;
  176. if (p == root)
  177. root = v;
  178. v->pred = p->pred;
  179. if (p->pred != nullptr) {
  180. if (p->pred->right == p)
  181. p->pred->right = v;
  182. else
  183. p->pred->left = v;
  184. }
  185. p->pred = v;
  186. if (p->right == v) { // its right
  187. p->right = v->right;
  188. if (p->right != nullptr)
  189. p->right->pred = p;
  190. v->right = p;
  191. if (v->right != nullptr)
  192. v->right->pred = v;
  193. } else {
  194. p->left = v->left;
  195. if (p->left != nullptr)
  196. p->left->pred = p;
  197. v->left = p;
  198. if (v->left != nullptr)
  199. v->left->pred = v;
  200. }
  201. }
  202. print_node(root);
  203. }
  204.  
  205.  
  206.  
  207.  
  208.  
  209. #include<bits/stdc++.h>
  210. #define LINT long long int
  211.  
  212. using namespace std;
  213.  
  214. struct Comp {
  215. int start_time;
  216. int end_time;
  217. int cost;
  218.  
  219. Comp(int s, int e, int c) : start_time(s), end_time(e), cost(c){}
  220.  
  221. Comp() : start_time(0), end_time(0), cost(0){}
  222. };
  223.  
  224. int main()
  225. {
  226. int a;
  227. cin >> a;
  228. vector<pair<int, LINT> > s; // cost
  229. vector<pair<int, LINT> > s1; // time
  230. vector<Comp> vc(a, *(new Comp()));
  231. for (auto& x : vc) {
  232. cin >> x.start_time >> x.end_time >> x.cost;
  233. }
  234. sort(vc.begin(), vc.end(), [](Comp& a, Comp& b){return a.start_time < b.start_time;});
  235. LINT prev = 0;
  236. for (const auto& x : vc) {
  237. prev += x.cost;
  238. s.push_back({x.start_time, prev});
  239. }
  240. sort(vc.begin(), vc.end(), [](Comp& a, Comp& b){return a.end_time < b.end_time;});
  241. prev = 0;
  242. for (const auto& x : vc) {
  243. prev += x.end_time - x.start_time;
  244. s1.push_back({x.end_time, prev});
  245. }
  246. int b;
  247. cin >> b;
  248. for (int i = 0; i < b; ++i) {
  249. int a1, a2, a3;
  250. cin >> a1 >> a2 >> a3;
  251. if (a3 == 1) {
  252. auto l = upper_bound(s.begin(), s.end(), pair<int, LINT>({a1, INT64_MIN}));
  253. auto r = upper_bound(l, s.end(), pair<int, LINT>({a2, INT64_MAX}));
  254. if (r == s.begin()) {
  255. cout << 0 << ' ';
  256. continue;
  257. }
  258. if (l == s.begin()) {
  259. r--;
  260. cout << r->second << ' ';
  261. continue;
  262. }
  263. l--;
  264. r--;
  265. cout << r->second - l->second << ' ';
  266. } else {
  267. auto l = upper_bound(s1.begin(), s1.end(), pair<int, LINT>({a1, INT64_MIN}));
  268. auto r = upper_bound(l, s1.end(), pair<int, LINT>({a2, INT64_MAX}));
  269. if (r == s1.begin()) {
  270. cout << 0 << ' ';
  271. continue;
  272. }
  273. if (l == s1.begin()) {
  274. r--;
  275. cout << r->second << ' ';
  276. continue;
  277. }
  278. l--;
  279. r--;
  280. cout << r->second - l->second << ' ';
  281. }
  282. }
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement